简体   繁体   English

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

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

The task is to open an application called t32 from the command line in a linuix machine using python script and 2 arguments is what I understand.任务是使用 python 脚本从 linuix 机器的命令行打开一个名为 t32 的应用程序,我理解的是 2 arguments。 but i am facing the following error:但我面临以下错误:

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'

note: i have already set the TEMP path注意:我已经设置了 TEMP 路径

It appears that variable cmmfilename is unset therefore causes and error when you are joining it with the string values.变量cmmfilename似乎未设置,因此在您将其与字符串值连接时会导致错误。 You should provide the code on how you call this Python script and how this script parses these arguments. For example: python main.py --filename="/sample_dir" and parser.add_argument("--filename", help="Working directory.") .您应该提供有关如何调用此 Python 脚本以及此脚本如何解析这些 arguments 的代码。例如: python main.py --filename="/sample_dir" and parser.add_argument("--filename", help="Working directory.")

You may also want to lookup on how to provide and read command line arguments (for example, see this question) as there are multiple ways in doing so.您可能还想查找如何提供和读取命令行 arguments(例如,请参阅问题),因为这样做有多种方法。

Replace the following in t32start.py line 318在 t32start.py 第 318 行中替换以下内容

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

with

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

This uses a more generic cross-platform approach to getting the temporary directory.这使用更通用的跨平台方法来获取临时目录。 In the current code, os.getenv('TEMP') returns None which cannot be concatenated with the trailing string.在当前代码中, os.getenv('TEMP')返回None ,它不能与尾随字符串连接。

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

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