En Wed, 25 Feb 2009 16:48:16 -0200, <chr...@fsfe.org> escribió:

update: i've found one, but this only works if the exception is raised
at a point determined by the outside.

to explain why this is applicable: in the examples, i used `1/0` to
raise a zero division exception inside the module whose scope i want to
preserve. in my practical application, the exception is thrown by a
function that was previously prepared by the outside module and monkey
patched to where the inner module is expected to call a method from (in
my case, the gtk main loop).

now if the function raising the exception saves both
`sys._getframe().f_back.f_globals` and a .copy() of that dictionary, the
original dictionary can later (when the exception is caught and the
module's globals are all None) be .update()d with the copy, and the
original module globals are restored.

That makes a strange situation where the module doesn't exist in sys.modules but its globals are still alive...

as said, this is just a workaround -- the original question still
remains open.

I'd try to move all the global stuff in that module into a function, "init". Importing the module will always succeed - you have to manually call init() after importing it.

--
Gabriel Genellina

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

Reply via email to