Io farei cosi':
a=['p4=p3+10','p1=10', 'p2=p1', 'p3=p1+p2']
n = 0
while a:
na = len(a)
try:
exec(a[n])
except NameError,e:
print e
n+=1
continue
n=0
x = a.pop(0)
provandolo ottengo:
>>> a=['p4=p3+10','p1=10', 'p2=p1', 'p3=p1+p2']
>>> n = 0
>>> while a:
... na = len(a)
... try:
... exec(a[n])
... except NameError,e:
... print e
... n+=1
... continue
... n=0
... x = a.pop(0)
...
>>> p4
30
>>> p3
20
>>> p1
10
>>> p2
10
Ciao
Stefano
2011/7/8 Matteo Boscolo <[email protected]>
> Ciao a tutti,
> ho questa lista:
> a=['p1=10', 'p2=20', 'p3=p1+p2']
>
> e questa funzione:
> def e(var):
> for aa in var:
> print aa
> exec(aa)
> print "p3",p3
> e(a)
> >>>p3 30
>
> adesso le cose si complicano
>
> a=['p4=p3+10','p1=10', 'p2=p1', 'p3=p1+p2']
>
> def e(var):
> for aa in var:
> print aa
> exec(aa)
> print "p4",p4
> e(a)
>
> Naturalmente qui si rompe tutto ..
>
> Avete qualche link / suggerimento che risolve questo tipo di problematica??
>
> Grazie mille
> Matteo
> ______________________________**_________________
> Python mailing list
> [email protected]
> http://lists.python.it/**mailman/listinfo/python<http://lists.python.it/mailman/listinfo/python>
>
_______________________________________________
Python mailing list
[email protected]
http://lists.python.it/mailman/listinfo/python