我有一个与内置模块冲突的模块.例如,在中myapp.email定义的模块myapp/email.py.
我可以myapp.email在我的代码中的任何地方引用而没有问 但是,我需要从我的电子邮件模块中引用内置电子邮件模块.
# myapp/email.py
from email import message_from_string
Run Code Online (Sandbox Code Playgroud)
它只发现自己,因此提出了一个ImportError,因为myapp.email没有message_from_string方法. import email我尝试时会导致同样的问题email.message_from_string.
有没有本地支持在Python中执行此操作,或者我是否仍然将我的"电子邮件"模块重命名为更具体的内容?
我似乎无法导入电子邮件模块.每次我这样做都会出错.我已经尝试卸载Python并重新安装,但电子邮件模块只是拒绝工作.我甚至完成了"点击安装电子邮件",它仍然被打破了.我使用的是Windows 7 Home Premium x64,运行x86版本的Python.
这是发生的事情:
c:\Users\Nicholas\Desktop>python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "email.py", line 1, in <module>
import smtplib
File "C:\Python27\lib\smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
>>>
Run Code Online (Sandbox Code Playgroud)
编辑:我已经尝试过python.org和ActivePython中的Python,认为ActivePython可能有效.反正有没有完全删除python及其所有数据并开始100%新鲜?