开发者

Python Class in module not loading in one computer, but the other

开发者 https://www.devze.com 2023-01-11 03:01 出处:网络
So I have two files: File 1 has this method in it: import MyGlobals global old_function def init(): import ModuleB

So I have two files: File 1 has this method in it:

import MyGlobals
global old_function
def init():
    import ModuleB
    global old_function
    MyGlobals.SomeNumber = 0
    old_function = ModuleB.someClass.function
    ModuleB.someClass.function = someNewFunction

File 2 has a class "someClass" and a class "someOtherClass". That being said. When I run my code on my computer it works great and it does what I expect it to. When I run this code on my friends computer which is the same build of windows 7 with the same python version 2.5.4, and with the same code(on a thumb d开发者_如何学运维rive for both) it gets an error "Module does not contain someClass"

I hope this makes sense in what I am trying to say. It is work related therefore code snippets aren't aloud. This one has me extremely stumped on why this would be the case. I even tried "from ModuleB import someClass" to see if someClass would work, but it still said that someClass is not in moduleB, while someCLass is definitely in moduleB...

Any ideas would greatly be appreciated!


Well, it's fairly clear that you are using different versions of ModuleB. I would hazard a guess that even though you are running the code from a thumb drive, you have put ModuleB.py somewhere else in your PYTHONPATH and it is running that version on your computer, but not on your friend's. This is easy to check:

import ModuleB
print ModuleB.__file__

I'll bet that doesn't print what you're expecting!

On a different note, you don't need the first global declaration in your code snippet -- that's already the global scope.

0

精彩评论

暂无评论...
验证码 换一张
取 消