我有以下文件结构:
main.py
Core/
object_storage.py
setup_logger.py
main.py:
from Core import object_storage
#rest doesn't matter
object_storage.py:
from setup_logger import logger
#rest doesn't matter
setup_logger.py:
import logging
import sys
Log_Format = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(stream = sys.stdout,
format = Log_Format,
level = logging.INFO)
logger = logging.getLogger()
当我运行object_storage.py时,它可以完美地工作,但是当我想要运行main.py时,它会给出错误:
ModuleNotFoundError: No module named 'setup_logger'
我查看了 os.getcwd() 函数的结果,发现问题在于工作目录仍然停留在 main.py 所在的根目录,而我想要从 Core/object_storage.py 中导入 setup_logger。
有什么解决方法吗?