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

问题描述 投票:0回答:1

来自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'>

这怎么可能?

python django graphene-python
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.