class error

Alexander Kapps alex.kapps at web.de
Fri Mar 18 16:43:51 EDT 2011


On 18.03.2011 21:13, monkeys paw wrote:
> I have the following file:
>
> FileInfo.py:
>
> import UserDict

After this import statement, the name "UserDict" refers to the module.

> class FileInfo(UserDict):

Here you are trying to subclass the module. What you need instead is:

class FileInfo(UserDict.UserDict):

Alternatively, import the UserDict class from the UserDict module 
like so:

from UserDict import UserDict

Note, that the UserDict class is obsolete, you can subclass the dict 
type directly:

class FileInfo(dict):
     "store file metadata"
     def __init__(self, filename=None):
         dict.__init__(self)
         self["name"] = filename



More information about the Python-list mailing list