python click库is_flag的意思

阿星星
  • 489
import click

@click.option("--name", is_flag=True,help="get h")
def hello(name):
    pass

如题.

找了很多资料都不知道is_flag的含义..

回复
阅读 3.3k
1 个回答

Boolean flags are options that can be enabled or disabled. This can be accomplished by defining two flags in one go separated by a slash (/) for enabling or disabling the option. (If a slash is in an option string, Click automatically knows that it’s a boolean flag and will pass is_flag=True implicitly.) Click always wants you to provide an enable and disable flag so that you can change the default later.

显然这句话的意思就是告诉你,当slash(/,斜杠)在参数中的时候,需要打开为True

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏