[SciPy-dev] gui_thread and wxPython-22.214.171.124
Fernando.Perez at colorado.edu
Fri Oct 1 11:54:39 CDT 2004
Prabhu Ramachandran schrieb:
> I have a question that you might be able to help with. I want to do
> Create a module that shadows an existing module in the filesystem.
> Lets say, site-packages/wx/__init__.py. I want to create a new
> module with code that does something else (and not have to create
> a file!). Like say: "def f(): print 'hello world'", call that the "wx"
> module, and make Python believe nothing is wrong (insert it into
> sys.modules or whatever) then do a 'reload(wx)' to re-read the
> real __init__.py just like normal. I'd like the code to be simple
> and not have to use complex import hooks.
> Is this possible? If it is I could probably eliminate the wxPython
I think it is possible. You can fool python's idea of what a module is quite
In : sys.modules['code'] = sys.modules['time']
In : code.<TAB>
code.accept2dyear code.daylight code.strftime code.tzname
code.altzone code.gmtime code.strptime code.tzset
code.asctime code.localtime code.struct_time
code.clock code.mktime code.time
code.ctime code.sleep code.timezone
These are all time's functions :)
In : reload code
Out: <module 'time' from '/usr/lib/python2.3/lib-dynload/timemodule.so'>
So I think what you have in mind should work. My only concern is that you
seem to want to reload the _original_ wx/__init__.py, so I'm not sure I
understand correclty where you want to do the trapping. But overall, I think
this kind of game can _definitely_ be played from the outside of Wx. This is
one of the benefits of python's extremely strong dynamic nature.
More information about the Scipy-dev