Just came across the same problem but I've expanded on this a little.
Nice Tip by the way Mat.  I think reload isn't there in python 3 as
well.

def rehashModules(moduleObject):
    toDel = []
    reload = False
    if isinstance(moduleObject, __builtins__.__class__):
        for mod in dir(moduleObject):
            toDel.append(moduleObject.__name__ + "." + mod)
        toDel.append(moduleObject.__name__)
        globals_ = globals()
        gToDel = []
        for mod in toDel:
            if mod in sys.modules:
                print "Deleting from sys ::", mod
                del(sys.modules[mod])
            if mod in globals_:
                gToDel.append(mod)
        if gToDel:
            for g in gToDel:
                print "Deleting from globals ::", g
                globals().pop(g)
                reload = True
        if reload:
            print "import %s" % moduleObject.__name__
            exec("import %s" % moduleObject.__name__, globals())


On Apr 27, 6:11 pm, Matthew Chapman <[email protected]> wrote:
> When any modules is imported (for the first time) it is put into a
> dictionary "sys.modules". The module name is the key and the value is an
> module object. When a module is imported for a second time the import does a
> dictionary lookup first to see if has already been loaded. If the module is
> found in sys.modules it returns the module object.
>
> def removeModule(name):
>         if sys.modules.has_key(name):
>                 del(sys.modules[module])
>
> removeModule("savemanager")
> import savemanager as sm
>
> On Mon, Apr 27, 2009 at 6:42 AM, sukuba <[email protected]> wrote:
>
> > Hi all,
> > anyone have this problem? I've been a while using pyqt in maya, doing
> > interfaces with more or less success, but in the last days I've seen
> > an strange and annoying behaviour when I reload a module, like this:
>
> > import savemanager as sm
> > reload(sm)
>
> > Maya doesn't reload the module, so the debbuging is imposible and I
> > have to close Maya, open it again, and import the module.
> > This issue is slowing my work a lot, and I don't know what else to do,
> > because I did this reloads before and it used to work.
>
> > ¿¿??
>
>
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to