如何在Python中访问命令行参数? [英] How do I access command line arguments in Python?
本文介绍了如何在Python中访问命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用python创建我的项目设置设置,但我需要帮助获取命令行参数。
I use python to create my project settings setup, but I need help getting the command line arguments.
我在终端上尝试过:
$python myfile.py var1 var2 var3
b $ b
在我的Python文件中,我想使用输入的所有变量。
In my Python file, I want to use all variables that are input.
推荐答案
import sys
print(sys.argv)
更具体地说,如果你运行 python example.py one two three
:
More specifically, if you run python example.py one two three
:
>>> import sys
>>> print(sys.argv)
['example.py', 'one', 'two', 'three']
这篇关于如何在Python中访问命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文