Home Command line arguments as variable definition in Python
Reply: 0

Command line arguments as variable definition in Python

user774
1#
user774 Published in July 21, 2018, 1:44 pm

I'm trying to construct a (kind of template/wrapper) script, which is called with some undefined options

> the_script.py --foo=23 --bar=42 --narf=fjoord

which then creates a variable called foo=23, bar=42, narf='fjoord' inside it.

What's the way to do it? I tried with getopt, but it needs a second parameter, so I have to define which options to get and of course, I want to be able to define my variable names via command line. I tried OptionParser too, not sure how to deal with undefined options though.

So is the way manually parsing the sys.argv, or is there maybe a module out there, which does exactly the same thing?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.399071 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO