想要从程序外面将参数传人程序内部的做法:
利用sys这个模块来进行操作,
#!/usr/bin/python #filename:using_sys.py import sys print 'the command line arguments are:' for i in sys.argv: print i print '\n\n The PYTHONPATH is\n',sys.path,'\n' 结果显示:sys.argv这个参数就好比我们java中的额main函数中经常看到的argv[]
[root@fsailing1 python]# python using_sys.py we are studying python the command line arguments are: using_sys.py we are studying python The PYTHONPATH is ['/root/python', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/gtk-2.0']