ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • optparse
    python/응용 2022. 5. 22. 00:10
    import sys
    
    print(sys.argv)
    
    ####################################################################
    from optparse import OptionParser
    
    if __name__ == '__main__':
        usage = 'usage: %prog [options] arg1 arg2'
        parser = OptionParser(usage=usage)
        parser.add_option('-f', '--file', action='store', type='string', dest='filename',
                          help='file name')  # myprog.py -f input.txt
        parser.add_option('-n', '--num', action='store', type='int', dest='num', help='number')  # myprog.py -n 10
        parser.add_option('-v', action='store_true', dest='verbose', default=True)  # myprog.py -v
        options, args = parser.parse_args()
        print(options)
        print(options.filename)
        print(args)

    'python > 응용' 카테고리의 다른 글

    pytest - fixture  (0) 2022.05.23
    pytest - basic  (0) 2022.05.23
    Thread - queue & PoisonPill  (0) 2022.05.23
    logging  (0) 2022.05.22
    yaml / configparser  (0) 2022.05.21

    댓글

Designed by Tistory.