gpt4 book ai didi

Python 为什么要导入内置函数

转载 作者:行者123 更新时间:2023-12-01 00:05:06 26 4
gpt4 key购买 nike

解析器.py

foo = 27

bar.py

import parser
print(parser.foo)

这不起作用,因为正在使用内置解析器库,而不是驻留在同一目录中的 parser.py

我该如何解决这个问题?我认为当出现名称冲突时,您自己的模块优先。

最佳答案

来自https://docs.python.org/3/tutorial/modules.html#the-module-search-path :

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path.

关于Python 为什么要导入内置函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60028359/

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