gpt4 book ai didi

python - 我可以将我的文件命名为 logging.py

转载 作者:行者123 更新时间:2023-11-28 19:05:07 29 4
gpt4 key购买 nike

所以我想要一个日志包装文件 - 它位于这样的目录中:

| team
-- | libraries
-- | logging.py
-- | __init__.py

问题是我在日志记录中做的:

from logging import ....

这是原生的 Python 日志记录机制。因此,在为我的日志记录包装器编写测试时,或者在其他地方导入它时,例如 import team.libraries.logging

上面一行失败了,因为我认为它试图从本地日志文件导入。

所以我的问题是:

最好更改 python 尝试导入的顺序吗?即首先尝试安装 python 的位置等?这是好的做法吗?

还是只更改我的本地文件名更好?

PS:我会重命名文件,因为它更容易,但仍然 - 有办法这样做吗?有可能吗?

最佳答案

Would it be best to change the order in which python tries to import? i.e. first try on where the python is installed etc? Is it good practise?

没有。显然不是。

Or better to just change my local file name?

是的,当然。

所有原因都已在评论中解释并且非常明显。

关于python - 我可以将我的文件命名为 logging.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47871423/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com