简体   繁体   中英

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. 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

It appears that variable cmmfilename is unset therefore causes and error when you are joining it with the string values. 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.") .

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.

Replace the following in t32start.py line 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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