Windows环境中的sys.argv

时间:2015-06-22 13:52:57

标签: python windows python-3.x

我正在尝试使用这本书来学习python'一个字节的python'。代码:

import sys

print('the command line arguments are:')
for i in sys.argv:
    print(i)

print('\n\nThe PYTHONPATH is', sys.path, '\n')

输出:

the command line arguments are:
C:/Users/user/PycharmProjects/helloWorld/module_using_sys.py


The PYTHONPATH is ['C:\\Users\\user\\PycharmProjects\\helloWorld', 'C:\\Users\\user\\PycharmProjects\\helloWorld', 'C:\\Python34\\python34.zip', 'C:\\Python34\\DLLs', 'C:\\Python34\\lib', 'C:\\Python34', 'C:\\Python34\\lib\\site-packages'] 
当书上说输出应该是:

The command line arguments are:
module_using_sys.py
we
are
arguments


The PYTHONPATH is ['/tmp/py',
# many entries here, not shown here
'/Library/Python/2.7/site-packages',
'/usr/local/lib/python2.7/site-packages']

本书是为python 2编写的,而我使用的是python 3.我的问题是为什么会有区别?

1 个答案:

答案 0 :(得分:1)

您正在调用脚本错误

打开cmd(命令行提示符)并键入:

cd C:/Users/user/PycharmProjects/helloWorld/
module_using_sys.py we are arguments

您将获得正确的输出。