Simulating "getopt" in functions (newbie)
Thorsten Kampe
thorsten at thorstenkampe.de
Sat Sep 7 16:05:38 EDT 2002
Hi,
I want to simulate a "getopt"-like behaviour within a _function_. This
is to avoid having to define two functions: "function" and
"slightly_different_function".
If the function was a standalone program, it would work like this
("v" for "verbose"):
$ function.py 5
1
$ function.py -v 5
The result is: 1
I've thought of this to simulate it in a function:
def function(a, b=None):
if b == "v":
print "The result is: 1"
else:
print "1"
>>> function(5)
1
>>> function(5, "v")
The result is: 1
So: what is the "pythonic", "natural" way to do this in Python?
Thanks in advance,
Thorsten
More information about the Python-list
mailing list