- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我对 python add_option 感到有些困惑
我是这样写代码的
parser.add_option("-u", "--uniqueness",
action="store_true", dest="uniqueness", default=False)
稍后在 shell 中,我想写这样的东西:
if(the user input -u option):
do something
我的问题是,如何在 python 中编写“用户输入 -u 选项”?我尝试使用“if(parser.uniqueness)”,但是这个命令不起作用。顺便说一句,我正在使用 python 2.7.3(只是想知道这个命令是否与 python 3 中的命令不同)thx
最佳答案
首先,optparse
已弃用,因此您应该使用 argparse
- 但逻辑是相似的。
您需要先在某处执行 args = parser.parse_args()
,然后使用 :
if args.uniqueness:
# potato
关于python shell add_option问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14493945/
我有一些显示 WordPress 功能图像的代码。如果尚未设置特征图像,则应显示默认图像。由于某种原因,如果找不到特色图像,我的代码将返回 URL 参数的空白值。 所以输出代码显示为... 背景图片:
我目前正在学习 boost::program_options::options_description 库并遇到以下查询。当我们调用 boost::program_options::options_d
使用 flask 脚本的 add_option方法 我正在尝试将配置文件的名称传递到我的 create_app() 中,以便我可以配置 from_pyfile() -- Flask Instance
现在,当我在命令提示符中输入“python openweather.py --api=key --city=London --temp=fahrenheit ”时,我会得到所需的华氏温度输出,甚至是如
我在 optparse 中为 Option 和 OptionParser 写了一个子类。我正在重写 OptionParser 中的 add_option 函数以使其解析新关键字。以下是我的代码。 fr
我偶然发现了标题中定义的问题。我有一个创建 options_description 实例然后在其上使用 add_options() 的应用程序。与示例中的非常相似: options_descripti
我是一名优秀的程序员,十分优秀!