当前位置:   article > 正文

python带参数执行py文件

python带参数执行
"""
    python 执行带参数
    python test.py test.txt /home/charles /home/charles/target
"""

if __name__ == '__main__':
    import sys

    args = sys.argv
    print(args)
    # ['test.py', 'my.txt', '/home/charles', '/home/charles/target']

    py_file = args[0]  # 主文件   主文件路径省略,在当前文件夹运行
    data_file_name = args[1]  # 数据文件
    data_file_path = args[2]  # 数据文件 路径
    target_path = args[3]     # 结果存放路径

    print(py_file)
    print(data_file_name)
    print(data_file_path)
    print(target_path)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/893609
推荐阅读
相关标签
  

闽ICP备14008679号