【发布时间】:2019-03-07 00:36:10
【问题描述】:
假设我正在从命令行运行脚本;
$python hello.py
这个 hello.py 脚本将打印“你好,欢迎!”在下一行中,它会提示您输入名称。例子。
$python hello.py
"Hello, welcome!"
What is you name?:<here you enter the name and press enter for the program to continue>
相反,我想在调用脚本时解析我的名字。
$python hello.py <do something to parse the name>
我知道我们可以导入 sys 并且可以通过 args[1] 调用名称
我想知道是否有一种方法无需修改代码并更改我们通过命令行运行脚本的方式。
【问题讨论】:
标签: python parsing input command-line args