from sys import argv
script, first, second, third = argv
print "The script is called:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third
"""
Test Result:
bogon:~ myRMBP$ python /Users/myRMBP/Desktop/ex13.py first 2nd 3rd
The script is called: /Users/myRMBP/Desktop/ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd
"""
心得:还是比较生疏,多多练习
本文通过一个简单的 Python 脚本示例介绍了如何使用 sys 模块的 argv 属性来接收命令行参数。示例展示了如何将三个外部变量传递给脚本,并在脚本中打印这些变量的值。
206

被折叠的 条评论
为什么被折叠?



