Funguje to skvěle:
x = ['a','b','c','d','e','f']
y = ['1','2','3','4','5','6']
for element in zip(x,y):
exec ( '%s = %s' % element)
print a, b, c, d, e, f
1 2 3 4 5 6
print a + b + c + d + e + f
21
V.L.
Lansky, Milan napsal(a):
exec(p1 + '=' + str(h1))
-----Original Message-----
From: python-boun...@py.cz [mailto:python-boun...@py.cz] On Behalf Of "Ing.
Vladislav Ludík"
Sent: Tuesday, December 21, 2010 12:45 AM
To: Konference PyCZ
Subject: [python] vytvoření proměnných
Zdravím všechny,
poradí někdo účinnou a jednoduchou metodu vytvoření spojení názvů
proměnných s jejich hodnotami:
x => {p1, p2, p3, ...pn}
y => {h1, h2, h3, ...hn}
kde p jsou proměnné a h jsou jejich hodnoty.
Výsledkem by měly být deklarované proměnné s jejich hodnotami:
p1 = h1
p2 = h2
p2 = h3
.
.
pn = hn
Díky, zdraví
V.L.
_______________________________________________
Python mailing list
Python@py.cz
http://www.py.cz/mailman/listinfo/python
This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be copied,
disclosed to, retained or used by, any other party. If you are not an intended
recipient then please promptly delete this e-mail and any attachment and all
copies and inform the sender. Thank you.
_______________________________________________
Python mailing list
Python@py.cz
http://www.py.cz/mailman/listinfo/python
__________ Informace od NOD32 5721 (20101221) __________
Tato zprava byla proverena antivirovym systemem NOD32.
http://www.nod32.cz
_______________________________________________
Python mailing list
Python@py.cz
http://www.py.cz/mailman/listinfo/python