2019-04-24
阅读量:
428
理解python的命令行参数
到目前为止,我们已经使用raw_input()或input()[for integers]在python中进行了输入。还有另一种使用命令行参数的方法。每当我们想要在脚本开始之前给出输入时,必须给出命令行参数,而另一方面,raw_input()用于在python程序/脚本运行时获取输入。
例如,在UNIX环境中,'ls'命令的参数'-a'和'-l'给出不同的结果。
# Python code to demonstrate the use of 'sys' module
# for command line arguments
import sys
# command line arguments are stored in the form
# of list in sys.argv
argumentList = sys.argv
print argumentList
# Print the name of file
print sys.argv[0]
# Print the first argument after the name of file
print sys.argv[1]






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论