Re: [Python-es] Sobrecargar función
Catalin Lungu
lcatalin en siadv.com
Mie Feb 9 17:55:53 CET 2005
Hola Hernán,
*******************
def copy(self):
c = ldict(self) ------------- aqui has puesto dict o ldict
c._orden = self._orden[:]
return c
*****************
Si le pongo dict me da el error:
Traceback (most recent call last):
File "<pyshell#19>", line 1, in ?
pp=qq.copy()
File "C:\Programacion\Python\Modulos\ListDict.py", line 39, in copy
c._orden = self._orden[:]
AttributeError: 'dict' object has no attribute '_orden'
Si ta hace falta te pongo la clase entera.
----- Original Message -----
From: "Hernán Martínez Foffani" <hernan en orgmf.com.ar>
To: "La lista de python en castellano" <python-es en aditel.org>
Sent: Wednesday, February 09, 2005 5:21 PM
Subject: RE: [Python-es] Sobrecargar función
>>> Que habría que poner dentro de la función copy para que me devuelva
>>> una clase igual a ListDict.
>>>
>>> class ListDict(dict):
>>> def __init__(self, *args):
>>> self._orden = []
>>> dict.__init__(self, *args)
>>>
>>> *
>>> def copy(self):
>>> #codigo función copy
>>
>> Alcanzará con que hagas:
>>
>> import copy
>>
>> ...
>> def copy(self):
>> return copy.copy(self)
>> ...
>>
>
> Bue... Esa es fue respuesta de programador vago ;-)
> Sin usar el modulo copy y aprovechando el "copy-constructor"
> del tipo dict:
>
> ...
> def copy(self):
> c = ldict(self)
> c._orden = self._orden[:]
> return c
> ...
>
> -H.
>
>
> _______________________________________________
> Python-es mailing list
> Python-es en aditel.org
> http://listas.aditel.org/listinfo/python-es
Más información sobre la lista de distribución Python-es