how to run another file inside current file?

Terry Jan Reedy tjreedy at udel.edu
Sat May 18 12:39:16 EDT 2013


On 5/18/2013 7:15 AM, Kevin Xi wrote:
> Hi,
> It's better to specify version of python you work with.

Absolutely.


  I know nothing
> about python 3 but in python 2 you can do this with `exec`. Example:
>
>  > f = file('otherFile.py')
>  > exec f

Py 2 has execfile that does the above. Py 3 do as above except that exec 
is a function.

with open('otherfile.py') as f:
   exex(f)


> For more, read the doc:
> http://docs.python.org/2.7/reference/simple_stmts.html#the-exec-statement
> HTH







More information about the Python-list mailing list