Using Boolean Flags in Python Click Library (command line arguments)

前端 未结 2 976
耶瑟儿~
耶瑟儿~ 2021-02-03 23:29

I\'m trying to make a verbose flag for my Python program. Currently, I\'m doing this:

import click

#global variable
verboseFlag = False

#parse arguments
@click         


        
2条回答
  •  心在旅途
    2021-02-04 00:07

    The above answer was helpful, but this is what I ended up using. I thought I'd share since so many people are looking at this question:

    @click.command()
    @click.option('--verbose', '-v', is_flag=True, help="Print more output.")
    def main(verbose):
        if verbose:
            # do something
    
    if __name__ == "__main__":
        # pylint: disable=no-value-for-parameter
        main()
    

提交回复
热议问题