Python: Reading arguments passed into script

When writing Python scripts, sometimes you will need to read in the arguments given.

import sys
print sys.argv

Using pop() to retrieve the information, we pull out the stuff we need.

For example the script was called using:

python script.py admin@example.com mypass

Then the arguments can be retrieved using:

args = sys.argv

args.pop(0) # filename for current script
email = args.pop(0) # username/email
password = args.pop(0) # password

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog