En Fri, 16 Feb 2007 03:38:43 -0300, <[EMAIL PROTECTED]> escribió:

> Hello,
> I got this similar sample script from books:
> $ cat sampdict.py
> #!/usr/bin/python
> class  SampDict(dict):
> def __init__(self,  filename=None):
> self["name"] =  filename

Are you sure you copied it exactly as it appears? Where did you find it?

> But when I run it I got the errors:
>
>>>> from sampdict import SampDict
>>>>  SampDict("/etc/passwd")
> Traceback (most recent  call last):
> File "<stdin>", line 1, in ?
> File  "sampdict.py", line 4, in __init__
> self["name"] = filename
> AttributeError: SampDict instance has no attribute '__setitem__'

Usually, when you inherit from another class, you have to call the base  
class __init__ from inside your own. That is, put this line:
        dict.__init__(self)
as the firt statement on your __init__

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to