Some questions that I couldn’t figure out from reading the docs and some other questions.
1: I was stumped by “how do I actually retrieve the arguments” so I looked around and someone suggested to use the __dict __ function to access it like a dictionary. Which works, but is that the only way? This seems like a rather common thing but it doesn’t appear to be anywhere obvious in the docs. If I missed it, maybe someone can point it out? It definitely wasn’t at the top.
2: argparse was introduced in 2.7, but some people refuse to get newer versions of python and continue to stick to older ones like 2.5, 2.6 for reasons unknown to me. My solution for dealing with them is to take the argparse module and put it in my own script directory. Is there any problem with this solution? It seems to be working at least.
You can use the
parse_args()function to retrieve parameters. For example:To answer your second question, it’s not recommended that you do this. Simply adding the module won’t be sufficient since you might run into dependency issues (ie, internally, argparse may require something else that was only made available in 2.7). The older, but deprecated version of this is optparse.