簡體   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