为什么我无法从同一目录中导入模块?(Why can't I import a module from within the same directory?)

编程入门 行业动态 更新时间:2024-10-26 12:25:48
为什么我无法从同一目录中导入模块?(Why can't I import a module from within the same directory?)

如果我在目录main.py和somemodule.py有两个python模块,我可以使用import somemodule 。

./ main.py somemodule.py __init__.py

在Django应用程序中,我们有urls.py和views.py ,为什么在这种情况下不会import views工作? 但相对from . import views from . import views作品?

If I have two python modules in a directory main.py and somemodule.py, I can import somemodule by using import somemodule.

./ main.py somemodule.py __init__.py

In django application where we have urls.py and views.py, why won't import views work in this case? But relative import from . import views works?

最满意答案

这是因为python 3的导入风格,与Django无关。

阅读本文以获取更多详细信息: 导入语句python3中的更改

That's because of python 3 import style and is irrelevant to Django.

Read this for more details: Changes in import statement python3

更多推荐

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

发布评论

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

>www.elefans.com

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