How to read/process command line arguments?

后端 未结 17 2006
离开以前
离开以前 2020-11-21 05:14

I am originally a C programmer. I have seen numerous tricks and \"hacks\" to read many different arguments.

What are some of the ways Python programmers can do this

17条回答
  •  执念已碎
    2020-11-21 05:29

    My solution is entrypoint2. Example:

    from entrypoint2 import entrypoint
    @entrypoint
    def add(file, quiet=True): 
        ''' This function writes report.
    
        :param file: write report to FILE
        :param quiet: don't print status messages to stdout
        '''
        print file,quiet
    

    help text:

    usage: report.py [-h] [-q] [--debug] file
    
    This function writes report.
    
    positional arguments:
      file         write report to FILE
    
    optional arguments:
      -h, --help   show this help message and exit
      -q, --quiet  don't print status messages to stdout
      --debug      set logging level to DEBUG
    

提交回复
热议问题