简体   繁体   中英

Python could not identify class in module without parantheses

I just had an odd behavior in python which was that I defined a class in a module, and I tried to import it but the interpreter could not find the class.

# src/AudioBuffer.py
class AudioBuffer:

This could not be imported in a different file as

# src/Recorder.py
from AudioBuffer import AudioBuffer

Why could it not be found?

A picture of the stack trace when trying to import the AudioBuffer module inside a Recorder module

在此处输入图像描述

Edit: removed false assumption/conclusion of the problem Edit: Added stack trace

Make sure that you have an empty __init__.py file in the directory. Add a dot before the module name:

from .AudioBuffer import AudioBuffer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM