With Python's optparse module, how do you create an option that takes a variable number of arguments?

后端 未结 6 2161
终归单人心
终归单人心 2021-02-13 19:38

With Perl\'s Getopt::Long you can easily define command-line options that take a variable number of arguments:

foo.pl --files a.txt             --ve         


        
6条回答
  •  青春惊慌失措
    2021-02-13 20:15

    Here's one way: Take the fileLst generating string in as a string and then use http://docs.python.org/2/library/glob.html to do the expansion ugh this might not work without escaping the *

    Actually, got a better way: python myprog.py -V -l 1000 /home/dominic/radar/*.json <- If this is your command line

    parser, opts = parse_args()

    inFileLst = parser.largs

提交回复
热议问题