好吧,我的一个项目中有一些相当奇怪的行为,我希望有人可以告诉我原因.我的文件结构如下所示:
MainApp.py
res/
__init__.py
elements/
__init__.py
MainFrame.py
Run Code Online (Sandbox Code Playgroud)
在MainFrame.py中,我定义了一个名为RPMWindow的类,它扩展了wx.Frame.
在MainApp.py中,这有效:
from res.elements.MainFrame import *
Run Code Online (Sandbox Code Playgroud)
而这不是:
from res.elements.MainFrame import RPMWindow
Run Code Online (Sandbox Code Playgroud)
我意识到外卡导入不会伤害任何东西,但我更感兴趣的是理解为什么命名导入在外卡成功时失败.
使用类名时,我得到了这个回溯:
Traceback (most recent call last):
File "C:\myApps\eclipse\plugins\org.python.pydev.debug_1.5.6.2010033101\pysrc\pydevd.py", line 953, in <module>
debugger.run(setup['file'], None, None)
File "C:\myApps\eclipse\plugins\org.python.pydev.debug_1.5.6.2010033101\pysrc\pydevd.py", line 780, in run
execfile(file, globals, locals) #execute the script
File "C:\Documents and Settings\Daniel\workspace\RPM UI - V2\src\MainApp.py", line 2, in <module>
from res.elements.MainFrame import RPMWindow
File "C:\Documents and Settings\Daniel\workspace\RPM UI - V2\src\res\elements\MainFrame.py", line 2, in <module>
from res.elements.MenuBar import MenuBarBuilder
File "C:\Documents and Settings\Daniel\workspace\RPM …Run Code Online (Sandbox Code Playgroud)