include a file in a python program

Roy Smith roy at panix.com
Mon Sep 6 01:17:09 CEST 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