我的赋值要求“from”用作命令行输入的参数。你知道吗
p = optparse.OptionParser()
p.add_option("--from")
p.add_option("--to")
p.add_option("--file", default="carla_coder.ics")
options, arguments = p.parse_args()
print options.from
显然,“from”是一个Python关键字。。。有什么办法可以解决这个问题吗?基本上,脚本应该使用
file.py --from=dd/mm/yyyy --to=dd/mm/yyyy --file=file
使用Python的
getattr
函数:其行为类似于
options.from
,只是属性名不必遵循Python通常的变量命名规则(包括关键字冲突)。你知道吗使用the ^{} attribute 指定名称:
相关问题 更多 >
编程相关推荐