python/응용

optparse

wefree 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)