Mock command line arguments for Python script with `optparse`? -
a python script want use (called snakefood
) run commandline , takes commandline arguments, eg:
sfood /path/to/my/project
the parsing of commandline arguments happens in file called gendeps.py using optparse
. however, want use snakefood module script. there way can somehow mock passing of commandline arguments snakefood
or way of rewriting gendeps.py
doesn't depend on optparse
anymore?
you can assign new list sys.argv
:
import sys sys.argv = ['programname', '-iq', '-q', directory] gendeps.gendeps()
optparse
uses sys.argv[1:]
input when no explicit arguments have been passed in.
Comments
Post a Comment