Py学习  »  Python

在windows平台上的任何位置运行Python脚本

itthrill • 3 年前 • 1147 次点击  

我在我的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文件的完整路径来调用。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131117
 
1147 次点击  
文章 [ 1 ]  |  最新文章 3 年前