python - parameter passing to python3.x script from commandline -
i new python. write script if didn't pass value argument, should ask value argument. if passed, should pick value , continue.passing these values command line. tried below code , python throwing error saying variable not initialized.
if (filename == none) filename == "c:\\filename" print(filename)
command line call executing script:- script.py "c:\filename"
stack trace :- if(no_error == none) ^ syntaxerror: invalid syntax
sys module provides lots of options play command line arguments. below example might helpful you.
import sys #storing argument in string st=" ".join(sys.argv) #splitting list file name , storing in list var=st.split('=') if len(sys.argv)<2: print "enter argument\n" else: print 'argument found' print var[1]
Comments
Post a Comment