linux – Does Python have an argc argument?

linux – Does Python have an argc argument?

In python a list knows its length, so you can just do len(sys.argv) to get the number of elements in argv.

I often use a quick-n-dirty trick to read a fixed number of arguments from the command-line:

[filename] = sys.argv[1:]

in_file = open(filename)   # Dont need the r

This will assign the one argument to filename and raise an exception if there isnt exactly one argument.

linux – Does Python have an argc argument?

Youre better off looking at argparse for argument parsing.

http://docs.python.org/dev/library/argparse.html

Just makes it easy, no need to do the heavy lifting yourself.

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *