[pyar] ¿Este es el comportamiento esperado de dict()?

Lucas Liendo mindmaster en gmail.com
Mie Nov 4 21:24:19 ART 2015


En Python 2.7.6

In [4]: dict(key='a', **{1: 'a'})
Out[4]: {1: 'a', 'key': 'a'}

In [5]: d = {1: 'v'}

In [6]: dict(key='a', **d)
Out[6]: {1: 'v', 'key': 'a'}


Vos estas en Python 3.4.3 ¿Será esa la diferencia? Habria que ver que
diferencias en dict hay entre python 2 y 3

2015-11-04 21:14 GMT-03:00 Manuel Kaufmann <humitos en gmail.com>:

> Hola,
>
> Me acabo de encontrar con una situación interesante:
>
> Python 3.4.3 (default, Oct 14 2015, 20:28:29)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> d = {1: 'key number'}
> >>> dict(key='content data', **d)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: keyword arguments must be strings
> >>> d = {'1': 'key number'}
> >>> dict(key='content data', **d)
> {'1': 'key number', 'key': 'content data'}
> >>>
>
> ¿Creen que es correcto este comportamiento?
>
> ¿Porqué no puedo tener llaves numéricas en "d" y usarlo así "**d" en dict?
>
> Saludos,
>
> --
>
> Kaufmann Manuel
> -- http://elblogdehumitos.com.ar/
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
> Argentina - http://www.usla.org.ar
>



-- 

Saludos,
Lucas.

Radar : http://radar-monitoring.readthedocs.org/en/latest/index.html
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20151104/a30a0a41/attachment.html>


More information about the pyar mailing list