| Store | Cart

execfile() on file subclass or string

From: Brano Zarnovican <zarn...@pobox.sk>
24 Mar 2005 01:19:07 -0800
Hi !

I have a python script represented by a string.
I need to execute it in a context. 'exec' does
the job, but doesn't display the filename in
tracebacks. 'execfile' is displaying the filename
but it can only exec a script in a filesystem.

I have tried:
- to give exec a filename, like:

  exec script_content in dict({'__file__':'bla.py'})

  => didn't work (neighter with __name__)

- create an in-memory file subclassing 'file'

  class memfile(file):
    ..
    def read(self)..

  => also pointless as 'execfile' doesn't accept a file
    only a filename

Can you help me ?
The only problem I need to resolve is that I don't see
the script name in tracebacks.

Thanks,

BranoZ

PS: The script didn't came from the filesystem, but I know
  it's content and a name.

Recent Messages in this Thread
Brano Zarnovican Mar 24, 2005 09:19 am
Do Re Mi chel La Si Do Mar 24, 2005 12:40 pm
Fredrik Lundh Mar 24, 2005 01:36 pm
Brano Zarnovican Mar 24, 2005 03:05 pm
Messages in this thread