include a file in a python program

Roy Smith roy at panix.com
Sun Sep 5 19:17:09 EDT 2010


In article <4c8423d3$0$28657$c3e8da3 at news.astraweb.com>,
 Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:

> fp = open("python.txt")
> text = fp.read()
> fp.close()
> exec(text)

> But keep in mind that the contents of python.txt will be executed as if 
> you had typed it yourself. If you don't trust the source with your life 
> (or at least with the contents of your computer), don't execute it.

Well, this is true, but eval() or exec() isn't really exposing him to 
anything that import isn't.



More information about the Python-list mailing list