On 9/5/2010 7:12 PM, Steven D'Aprano 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.

Also, this executes the code within the namespace of the calling code rather than within a fresh module namespace. That could be either better or worse.

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to