[C++-sig] Reloading python code in BOOST environment

Kirsebom Nikolai nikolai.kirsebom at siemens.no
Fri Oct 17 11:13:29 CEST 2003


I have a problem in trying to 'reload' python code in an BOOST invironment.
Given the two files below.  When I open Python (in command prompt) and do
the following:

>>> import Wrap
>>> Wrap.Main()
5 abc

        # CHANGE CONTENT OF FILE Subber.py to have i = 6
>>> Wrap.Main()
6 abc
>>>

If I try to do the same in my application (change the Subber.py content)
without restarting the whole application,
the changes are not seen.  Does this have something to do with BOOST
environment, or is it probably in the Subber.py
file (which in my application is a wxPython dialog presenting some
information from the application (exposed objects
using BOOST)).
It would be so nice to not have to restart the application when only
changing the Python-code.

Thanks for any help.
Nikolai


----- File Wrap.py ------------------------------------
def Main():
    import sys,copy
    bi=copy.copy(sys.modules.keys())
    try:
        import Subber
        Subber.Main()
    except:
        raise ImportError, "Failed to import"
    ai=copy.copy(sys.modules.keys())
    for k in ai:
        if not k in bi:
          del sys.modules[k]

----- File Subber.py ---------------------------------
i = 5
a = 'abc'

def Main():
    print i, a






More information about the Cplusplus-sig mailing list