type(d) != type(d.copy()) when type(d).issubclass(dict)

Flávio Lisbôa flisboa.costa at gmail.com
Fri Dec 24 16:37:31 EST 2010


>
>  copy, here, is a dict method. It will create a dict.
> If you really need it, you could try this:
>
> import copy
> class neodict(dict):
>    def copy(self):
>        return copy.copy(self)
>
> d = neodict()
> print type(d)
> dd = d.copy()
> print type(dd)


One more gotcha to python... OO in python is strange :p

IMO, if i subclass a class, all instance methods from a subclass instance
should work with the subclass. But i'm guessing python doesn't make this
distinction of instance/class methods like some other languages do (unless
one uses annotations, what appears to be not the case with the dict class).

Not that it inhibits me on using python in any way, in fact i do use python
for my projects. I'm new to it, and I like some of its features, but some
others are rather strange.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101224/90c7a12d/attachment-0001.html>


More information about the Python-list mailing list