如何从看似错误的模块路径成功导入Python类?

时间:2017-12-15 21:44:47

标签: python django graphene-python

Graphene Django Integration官方文档中的以下行正常工作:

from graphene_django import DjangoObjectType

然而,课程DjangoObjectTypegraphene_django.types中定义,因为项目的source code可能会显示。

此外,在上述from

之后运行以下内容
import inspect
print(inspect.getmodule(DjangoObjectType))

产生此输出:

<module 'graphene_django.types' from '<myVirtualEnv>/lib/site-packages/graphene_django/types.py'>

这怎么可能?

1 个答案:

答案 0 :(得分:1)

the root of the package __init__.py从类型中导入所有名称,因此您可以从那里导入。