import os,sys for root,dirs,files in os.walk(sys.argv[1]): for name in files: print(os.path.join(root,name)) for name in dirs: print(os.path.join(root,name)) 要写sys.argv[1], python filename 参数 这里的参数是个路径…
为什么需要argparse 开门见山,举一个简易计算器代码的例子,其中sys.argv用来读取脚本执行时后面传入的参数. def calculator(x, y, operation): if "add" == operation: return x + y elif "mod" == operation: return x % y elif "sub" == operation: return x - y elif "div"…