我在我的windows机器(my_codes)中保存了一个文件夹,在那里我保存了所有代码。我已将此文件夹路径添加到windows path中的path env变量中。
现在,当我从某个地方调用脚本时,我无法正确地传递参数。
(base) C:\Users\abc>test.py abc.csv
print_test
C:\Users\abc\my_codes\test.py
Traceback (most recent call last):
File "C:\Users\abc\my_codes\test.py", line 4, in <module>
print(sys.argv[1])
IndexError: list index out of range
python代码如下所示。我已将其保存为测试。C:\Users\abc\my_代码中的py
import sys
print('print_test')
print(sys.argv[0])
print(sys.argv[1])
这在linux中运行得很好,但到目前为止无法在windows中运行。
如果我这么说的话,这也适用于窗户内部。
(base) C:\Users\abc>python my_codes/test.py abc.csv
print_test
my_codes/test.py
abc.csv
但是,我不想每次通过指定python文件的完整路径来调用。