On Mon, Oct 7, 2013 at 3:31 PM, Maria McKinley <[email protected]>wrote:
> I am using a python package that has a required command line option I am > suppose to use when I invoke my script if I am using their library. Kind of > weird, I know, I love required options! I want to load my class from the > python interpreter for testing purposes. Is there a way to specify options > from the python interpreter? > I'm a little confused about you use-case -- usually you would EITHER run the cocde from pyhthon with teh python API, OR run it as a command line script. but -- when a python script is run, the command line gets put into sys.argv -- you may be able to intercept the runing,a nd push something into sys.argv first: import sys sys.argv.extend(['-f', 'the_flag_option']) or just call the script as a separate process with os.system() or the subprocess module. This is for unit testing, so alternatively if there is a sensible way to > unit test scripts with command line options, that would work, but that > seems trickier. And honestly, the way this package is set up, not sure how > far I'm really going to get with unit testing, at all. :-( > well, running a full script with given commands may be autamted testing, but it'os not really unit testing... still good to do, though. HTH, -Chris -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
