【问题标题】:How to type in arguments in the middle of the code?如何在代码中间输入参数?
【发布时间】:2015-10-03 06:01:18
【问题描述】:

我们可以这样做来输入任何参数:

from sys import argv
script, argument_1, argument_2 = argv

是否可以在代码中间而不是开头输入参数?

我也想这样做:

print "La-la-la"
print "Any string"
# and here i want the program will take a file name as an argument to work with the file then

【问题讨论】:

  • 这个问题完全无法解读。我不知道你想完成什么。
  • 您可以随时查看 sys.argv。
  • 刺入黑暗:你的意思是input()
  • deceze,也许吧。它在 Python 2.7.10 中有效吗?
  • 在左上角的手册页上有一个选择器,可让您选择另一个 Python 版本...自己看看。

标签: python arguments


【解决方案1】:

看看argparse一个用于命令行解析的python类

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多