python - 导入 Python 类

标签 python import module

我的文件夹结构如下:

-PCore
    |-__init__.py
    |-PFnTransform.py
    |-PEuler.py
    |-PPoint3.py
    |-...

在每个 .py 文件中都有一个同名的类。

我只想通过写入导入:

from Core import PPoint3

但实际上我需要写:

from Core.PPoint3 import PPoint3

当我打印类(class)时,我得到 <class 'PCore.PEuler.PEuler'>而不是<class 'PCore.PEuler'> (我想要什么)

我需要在__init__.py中写什么文件?

最佳答案

__init__.py文件中,您需要导入PPoint3类。

from PPoint3 import PPoint3

然后,您将能够从 PCore 包中导入 PPoint3 类。

关于python - 导入 Python 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20428156/

相关文章:

python - Django ORM,如何使用 values() 并仍然使用 choicefield?

python - python 中的文本分类 - (基于 NLTK 句子)

python - 基本的 Python 导入问题

powershell - 在foreach循环中使用ADComputer输出

python - 如何在openkinect中停止和启动kinect?

python - 异常被执行两次并被不同的 except block 捕获

python - 为什么python 3.5找不到文件中导入的模块

当别名不在查询中时,MySQL 错误 "An alias was previously found"

python - 是否有用于访问 Advantage 数据库服务器的 Python 模块?

python - 调用 if __name__ == '__main__' : in one module from a function in another module