在Python3中的UserDict被移到了collections模块

最近写了一个Dive Into Python 里的那个FileInfo示例程序,使用到UserDict,

from UserDict import UserDict

在python2.6下是没有问题的,但是在python3中却出现Import Error,开始以为也许是被移掉了,后来还是在python官网上找到了答案,

Issue2876

msg66900 - (view)
Author: Brett Cannon (brett.cannon)
Date: 2008-05-16 04:49

In Python 3.0, the UserDict module was removed and the UserDict class was 
moved to the collections module. That change-over needs to be backported 
to 2.6 so that the UserDict module can be deprecated.
 
看来是要统一模块名称,涉及collections的东西都统统要放在一起.
逐将代码改为
from collections import UserDict
就没有问题了
posted @ 2009-12-17 15:44  落木萧萧  阅读(1757)  评论(1)    收藏  举报