class error

MRAB python at mrabarnett.plus.com
Fri Mar 18 16:33:10 EDT 2011


On 18/03/2011 20:13, monkeys paw wrote:
> I have the following file:
>
> FileInfo.py:
>
> import UserDict
>
> class FileInfo(UserDict):
>     "store file metadata"
>     def __init__(self, filename=None):
>         UserDict.__init__(self)
>         self["name"] = filename
>
>
>
> When i import it like so:
>
> import FileInfo
>
>
> i get this error:
>
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
>   File "FileInfo.py", line 3, in <module>
>     class FileInfo(UserDict):
> TypeError: Error when calling the metaclass bases
>     module.__init__() takes at most 2 arguments (3 given)
>
> What is causing the error?

You're importing the module "UserDict" and then trying to create a
subclass of it.

The module "UserDict" contains the class "UserDict".

You could write either:

     import UserDict

     class FileInfo(UserDict.UserDict):

or:

     from UserDict import UserDict

     class FileInfo(UserDict):



More information about the Python-list mailing list