【问题标题】:Python3 module pakaging files structure and init filePython3模块打包文件结构和init文件
【发布时间】:2019-02-01 20:43:42
【问题描述】:

我有一个 Python 模块,文件中有单个文件和单个函数。我已经将它上传到pypi,并使用以下结构来打包它,但是当我调用它在模块文件中的函数时,我收到了这个错误:

AttributeError: module 'effInput' has no attribute 'ask'

('ask' 是函数的名称)。

模块封装结构:

|--effInput
    |--__init__. py
    |--effInput.py (module file) 
|--setup.py
|--readme.txt
|--LICENSE

init.py 文件:

import effInput
name="EffInput"

我做错了什么?

【问题讨论】:

    标签: python-3.x module structure init


    【解决方案1】:

    当你这样做时,你必须调用effInput.effInput.ask 而不是effInput.ask。如果您在 __init__.py 中添加了 from effInput import *,它应该会按预期工作。

    【讨论】:

    • 我应该把 init.py 文件放在包根目录还是模块文件旁边?
    • 在模块文件旁边。
    猜你喜欢
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 2017-05-06
    • 2014-07-12
    相关资源
    最近更新 更多