[pyar] Algoritmo de agrupamiento

Roberto Alsina ralsina en netmanagers.com.ar
Mie Nov 16 09:29:04 ART 2011


On 11/16/2011 9:24 AM, Daniel wrote:
>> Hola, nose si lo pudiste resolver pero esto me funciono a mi:
> Aún sigo a las vueltas...
>> from operator import attrgetter
>> qs = Modelo.objects.filter(...)
>> sort = sorted(qs, key=attrgetter('campo1', 'campo2', 'campo3'))
> pero ¿qué significa attrgetter('campo1', 'campo2', 'campo3'))?
>
> no se qué poner ahí, pero investigo por ese lado

Google!

http://docs.python.org/library/operator.html

operator.attrgetter(/attr/[,/args.../])

    Return a callable object that fetches/attr/from its operand. If more
    than one attribute is requested, returns a tuple of attributes.
    After,f=attrgetter('name'), the callf(b)returnsb.name.
    After,f=attrgetter('name','date'), the callf(b)returns(b.name,b.date).


O sea, básicamente, convierte los atributos en métodos.
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20111116/6c88c432/attachment.html>


More information about the pyar mailing list