bjskistad bjskistad - 7 months ago 38
Python Question

How to execute file in Python with arguments using import?

I read that you can execute a file using

like this

#!/usr/bin/env python
import file2

#!/usr/bin/env python
print "Hello World!"

And will print
Hello World
. How would I execute this file with arguments, using


Program arguments are available in sys.argv and can be used by any module. You could change to

import sys
print "Here are my arguments", sys.argv

You can use the argparse module for more complex parsing.