If you want to do this in your python script, you can arrange for it to take a list of integers by using the argparse
module (untested code):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('rfile', type=argparse.FileType('r'))
parser.add_argument('numbers', nargs='+', type=int)
ns = parser.parse_args()
Such activities are usually conducted under the auspices of a main
function as explained by Jon-Eric.
If you call the resulting script from the shell with
python the_script.py filename 1 2 3 4 5 6
you will end up with ns.file
being equal to the file filename
, opened for read access, and ns.numbers
being equal to the list [1, 2, 3, 4, 5, 6]
.
argparse
is totally awesome and even prints out usage information for the script and its options if you call it with --help
. You can customize it in far too many ways to explain here, just read the docs.
argparse
is in the standard library as of Python 2.7; for earlier pythons it can be installed as a module in the normal way, e.g. via easy_install argparse
, or by virtue of being a dependency of the package that your script is part of.