python 如何处理同名的模块和包? [英] How python deals with module and package having the same name?

查看:22
本文介绍了python 如何处理同名的模块和包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个模块 foo.py 和一个包 foo/.如果我打电话

Suppose I have a module foo.py and a package foo/. If I call

import foo

会加载哪一个?如何指定我要加载模块或包?

which one will be loaded? How can I specify I want to load the module, or the package?

推荐答案

我相信包总是会被加载的.据我所知,你无法解决这个问题.因此,更改包或模块名称.文档:http://docs.python.org/tutorial/modules.html#the-module-search-path

I believe the package will always get loaded. You can't work around this, as far as I know. So change either the package or the module name. Docs: http://docs.python.org/tutorial/modules.html#the-module-search-path

这篇关于python 如何处理同名的模块和包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆