HowTo exec every line of a file inside python program

Tim Hochberg tim.hochberg at ieee.org
Wed Feb 11 10:52:34 EST 2004


Joe Richett wrote:

> Hi all,
> 
> I have a python program and I have some "user defined" command stored in 
> a separate text file. Is there a builtin command with which I can load 
> the "user defined"-file and execute every command line by line, e.g.

Look up execfile under built-in functions is the docs.

-tim




> 
> #
> # MAIN PROGRAM
> #
> 
> def a(i):
>   print "here we are #", i
> 
> if __name__ == "__main__":
>   for i in range(10):
>     a(i)
>     <execute everything from FILE.PY>
> 
> ------------------------------------------------------
> 
> #
> # USER DEFINED FILE
> #
> print "here we are in the user defined file"
> 
> 





More information about the Python-list mailing list