so I wrote a program and I want to pass it either a filename and an integer or just an integer. Whats the best way to determine which argument is the integer? This is what I have:
import sys
if len(sys.argv) > 1):
for e in sys.argv:
try:
bio = map(e, int)
except:
pass
thanks in advance
You could check whether or not the argument is an integer with the string
isdigit()method:But, I should encourage you to give a chance to the argparse library: http://docs.python.org/dev/library/argparse.html