我有三个模块:为什么Python导入不工作?
plugin_grt.py
fragments.py
helpers.py
就在plugin_grt.py顶部我
from jpa_export_helpers import SourceFile, Mysql, Conv, Columns, Column, Table, ForeignKey, Index, Catalog, Inheritance
这作品,这是我可以使用Table.whateverMethod(...)没有问题。现在,当我将相同的导入添加到fragments.py模块的顶部时,我得到:
Traceback (most recent call last):
File "C:\Users\Kawu\AppData\Roaming\MySQL\Workbench\modules\jpa_export_plugin_grt.py", line 53, in <module>
from jpa_export_helpers import SourceFile, Mysql, Conv, Columns, Column, Table, ForeignKey, Index, Catalog, Inheritance
File "C:\Users\Kawu\AppData\Roaming\MySQL\Workbench\modules\jpa_export_helpers.py", line 2, in <module>
from jpa_export_fragments import Type, EnumValue
File "C:\Users\Kawu\AppData\Roaming\MySQL\Workbench\modules\jpa_export_fragments.py", line 2, in <module>
from jpa_export_helpers import SourceFile, Mysql, Conv, Columns, Column, Table, ForeignKey, Index, Catalog, Inheritance
ImportError: cannot import name SourceFile
为什么不能正常工作?唯一的解决方法是正确的导入类需要它们的地方,但它不是我喜欢的东西(至少目前如此):
def getPrimaryKeyColumns(self):
from jpa_export_helpers import Columns
return Columns.getPrimaryKeyColumns(self.table.columns)
注意,我原本一个Java家伙,所以进口“随意”对我来说似乎很陌生。无论如何,这里有什么问题?
'jpa_export_fragments'和'jpa_export_helpers'是你的吗?毕竟他们正在造成错误。 'plugin_grt'不是问题。 – delnan 2011-04-16 12:49:22
注意到plugins_grt和fragments的输入是什么,按什么顺序会使问题(和问题)更加清晰。 – msw 2011-04-16 13:06:46