<p>Ciao!</p><p>Prova a partire da questo esempio:</p><p>>>> oldlocals=locals().keys()<br>>>> a,b,c,d = 1,2,3,4<br>>>> newlocals=locals().keys()<br>>>> oldlocals<br>['__builtins__', '__file__', '__name__', 'readline', 'rlcompleter', '__doc__']<br>
>>> newlocals<br>['a', 'oldlocals', 'b', 'd', '__builtins__', '__file__', 'c', '__name__', 'readline', 'rlcompleter', '__doc__']<br>
>>> newly_defined=set(newlocals).difference(oldlocals).difference(set(('oldlocals',)))<br>>>> newly_defined<br>set(['a', 'c', 'b', 'd'])<br>>>> a,b,c,d<br>
(1, 2, 3, 4)<br>>>> for var in newly_defined: del(locals()[var])<br>...<br>>>> a,b,c,d<br>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br>NameError: name 'a' is not defined<br>
>>><br><br></p><br><div class="gmail_quote">2008/10/25 <span dir="ltr"><<a href="mailto:michele@nectarine.it" target="_blank">michele@nectarine.it</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Ciao,<br>
ad un certo punto del programma volevo eliminare tutti le variabili e<br>
gli oggetti creati, ad eccezione delle import che ho fatto; per cui ho<br>
agito così:<br>
<br>
for i in dir()[:]:<br>
del i<br>
<br>
Mi sembrava ragionevole e così l'ho fatto girare:<br>
>>> dir()<br>
['__builtins__', '__doc__', '__name__', 'a', 'b', 'c', 'random']<br>
>>> for i in dir()[:]:<br>
... del i<br>
...<br>
>>> dir()<br>
['__builtins__', '__doc__', '__name__', 'a', 'b', 'c', 'random']<br>
>>><br>
<br>
Però non ha funzionato :-)<br>
<br>
Come posso eliminare, nel mio esempio, tutte le variabili create?<br>
<br>
Vi ringrazio.<br>
<br>
_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@lists.python.it" target="_blank">Python@lists.python.it</a><br>
<a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a><br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br><a href="http://alepisa.blogspot.com" target="_blank">http://alepisa.blogspot.com</a><br>Esalando Prassi<br>