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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -