Python:从1级以上导入(Python: importing from 1+ levels down)

编程入门 行业动态 更新时间:2024-10-28 18:36:46
Python:从1级以上导入(Python: importing from 1+ levels down)

假设我使用不必要的长路径导入:

from pandas.core.series import Series

更常见的导入是:

from pandas import Series

我可以通过以下方式查看完整路径:

Series Out[6]: pandas.core.series.Series

这是我困惑的根源。 在顶级__init__模块中没有任何地方可以from core import * (或core.series ) from core import *任何内容。 .core的__init__模块也是空的。

是什么使我能够简单地使用from pandas import Series而不是完整路径,或者更一般地说,导入一个“几级降低”的模块,函数,变量或类?

Say that I import with the unnecessarily long full path:

from pandas.core.series import Series

The more common import is simply:

from pandas import Series

to which I can view the full path with:

Series Out[6]: pandas.core.series.Series

Here is the source of my confusion. Nowhere in the top-level __init__ module is there any import of from core import * (or core.series, for that matter). The __init__ module for .core is empty also.

What enables me to be able to use simply from pandas import Series rather than the full path or, more generally, to import a module, function, variable, or class that is "several levels down"?

最满意答案

你有__init__.py文件内 :

from pandas.core.api import *

其中导入Series 。

You have inside the __init__.py file:

from pandas.core.api import *

in which Series is imported.

更多推荐

本文发布于:2023-08-08 00:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466706.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   importing   levels

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!