繁体   English   中英

如何使用 argv 在 linuix 上运行 python 脚本文件?

[英]how to run a python script file on linuix with argv?

任务是使用 python 脚本从 linuix 机器的命令行打开一个名为 t32 的应用程序,我理解的是 2 arguments。 但我面临以下错误:

sh-5.0$ python2 t32start.py --t32path /home/uif24704/t32 --target makena
Python not detected in PATH. Attempting to add python executable path to PATH
Added Python directory /usr/bin to PATH
Selected target: makena
Selected session: None
Traceback (most recent call last):
File "t32start.py", line 847, in <module>
generate_buildinfo()
File "t32start.py", line 318, in generate_buildinfo
tmpfile = os.getenv('TEMP') + os.sep + cmmfilename
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

注意:我已经设置了 TEMP 路径

变量cmmfilename似乎未设置,因此在您将其与字符串值连接时会导致错误。 您应该提供有关如何调用此 Python 脚本以及此脚本如何解析这些 arguments 的代码。例如: python main.py --filename="/sample_dir" and parser.add_argument("--filename", help="Working directory.")

您可能还想查找如何提供和读取命令行 arguments(例如,请参阅问题),因为这样做有多种方法。

在 t32start.py 第 318 行中替换以下内容

tmpfile = os.getenv('TEMP') + os.sep + cmmfilename

import tempfile
tmpfile = tempfile.gettempdir() + os.sep + cmmfilename

这使用更通用的跨平台方法来获取临时目录。 在当前代码中, os.getenv('TEMP')返回None ,它不能与尾随字符串连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM