command line arguments - can't pass arguements using argparse and python 3.4.2 on Windows 7 -
i've upgraded python 3.4.2 , argparse (from optparse) neither appears recognise command line options. simple test run this;
#test_argparse.py def main(): import argparse parser = argparse.argumentparser(description='execute database query.') parser.add_argument("-q", "--query", dest="query", help="name of query file run") args = parser.parse_args() print(args) if __name__ == '__main__': main()
from command line, when run
test_argparse.py -q get_msre_for_book
i get:
namespace(query=none)
but when run within ide:
*** python 3.4.2rc1 (v3.4.2rc1:8711a0951384, sep 21 2014, 21:16:45) [msc v.1600 32 bit (intel)] on win32. *** command line : -q get_msre_for_book namespace(query='get_msre_for_book')
i'm trying launch script via
os.system('python.exe', '<path script>test_argparse.py -q get_msre_for_book')
but fails no query presented shown above. i've worked round launching using
subprocess.call
but i'd rather not have to. again, suggestions or ideas gratefully received.
to give closure question, these 2 comments solve problem:
there earlier questions passing commandline arguments in windows 7. solutions involve getting registry link right. stackoverflow.com/questions/2640971, stackoverflow.com/questions/9880540. e,g, "c:\python\python33\python.exe" "%1" %*.
that fixed - thank - precise registry entry needs c:\python\python33\python.exe" "%1" %" (added final double quote)
Comments
Post a Comment