Python: how to parse strings in command-line arguments? -



Python: how to parse strings in command-line arguments? -

hi i'm trying pass string through arguments in python 3.4 using sys , getopt when seek run test.p -t "this test phrase." , print argument recieved -t i'll "this.

test.py:

def main(argv): try: opts, args = getopt.getopt(argv,"ht:",["test=", "testphrase="]) except getopt.getopterror: print('ngram.py <options>') sys.exit(2) opt, arg in opts: if opt == ('-h', "--help"): print('test.py <options>') # add together missing options sys.exit() elif opt in ("-t", "--test", "--testphrase"): global testphrase testphrase = arg print(testphrase) if __name__ == "__main__": main(sys.argv[1:])

how can prepare this, prints this test phrase., instead of "this?

string python-3.x command-line-arguments getopt sys

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -