How can I use the option more than one time?
for example the command cpdoc:
cpdoc -d text -s x -s y -s z
I would like to have x,y,z in one array/data structure
import optparse
import os
import shutil
def main():
p = optparse.OptionParser()
folder = []
p.add_option('--source', '-s',help="source folder")
p.add_option('--destination', '-d')
options, arguments = p.parse_args()
if options.source and options.destination:
if not os.path.exists(options.destination):
os.makedirs(options.destination)
for source in options.source:
#do some stuff in each source
else:
p.print_help()
if __name__ == '__main__':
main()
use the argparse module instead
Stolen without shame from the docs:
If -t3 is seen on the command-line, optparse does the equivalent of:
If, a little later on, –tracks=4 is seen, it does: