社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

J Arun Mani

J Arun Mani 最近回复了
6 年前
回复了 J Arun Mani 创建的主题 » 如何在一个文件中分别运行多个python方法[关闭]

所以从你的评论来看,我认为你希望:

def method1(arg):
    print("hello", arg)

def method2(arg):
    print("Whatsup", arg)

if __name__ == "__main__":
    import sys
    #print(sys.argv)
    func = sys.argv[1]
    arg = sys.argv[2]
    if func == "method1": method1(arg)
    elif func == "method2": method2(arg)

现在运行这个 python3 hello.py method1 John 这是一个肮脏的例子,如果你想要更多的选择,你需要调整很多。