PEP263 and execfile()

Rainer Deyke rainerd at
Tue Nov 18 08:48:56 CET 2003

Roman Suzi wrote:
> But is there solution possible without modification of
> all those files I do execfile() on?

Instead of using execfile, you can read the files, add text to them in
memory, and exec the result.  Something like this:

def execfile_with_prepend(fname, text_to_prepend):
  text = text_to_prepend + open(fname).read()
  exec text in {}

Rainer Deyke - rainerd at -

More information about the Python-list mailing list