[pyar] Patrones de diseño: Strategy

Matías Bellone matiasbellone en gmail.com
Mie Feb 21 10:32:43 -03 2018


2018-02-21 8:16 GMT-03:00 Luis Andraschnik <luis.andraschnik en gmail.com>:

> Hola Matías
>
> Está muy bueno, pero eso es la magia de Python verdad, sino no es posible
> evitar el if ..else ...(salvo con diccionarios) ?   No conocía el
> diccionario locals() ni globals() gracias!!
>
>
> Según la definición de getattr(*object*, *name*[, *default*]) :
>
> Return the value of the named attribute of *object*. *name* must be a
> string. If the string is the name of one of the object’s attributes, the
> result is the value of that attribute. For example,* getattr(x, 'foobar')
> is equivalent to x.foobar*. If the named attribute does not exist,
> *default* is returned if provided, otherwise AttributeError
> <https://docs.python.org/3/library/exceptions.html#AttributeError> is
> raised.
> ¿Puedo hacer funcion = self.'leer_{}'.format(extension) ?
>

No... justamente por eso está getattr, para poder usar una cadena en lugar
de un literal.

Saludos,
Toote
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20180221/2db4f8ae/attachment.html>


Más información sobre la lista de distribución pyar