<p>Ciao!</p><p>Prova a partire da questo esempio:</p><p>&gt;&gt;&gt; oldlocals=locals().keys()<br>&gt;&gt;&gt; a,b,c,d = 1,2,3,4<br>&gt;&gt;&gt; newlocals=locals().keys()<br>&gt;&gt;&gt; oldlocals<br>[&#39;__builtins__&#39;, &#39;__file__&#39;, &#39;__name__&#39;, &#39;readline&#39;, &#39;rlcompleter&#39;, &#39;__doc__&#39;]<br>
&gt;&gt;&gt; newlocals<br>[&#39;a&#39;, &#39;oldlocals&#39;, &#39;b&#39;, &#39;d&#39;, &#39;__builtins__&#39;, &#39;__file__&#39;, &#39;c&#39;, &#39;__name__&#39;, &#39;readline&#39;, &#39;rlcompleter&#39;, &#39;__doc__&#39;]<br>
&gt;&gt;&gt; newly_defined=set(newlocals).difference(oldlocals).difference(set((&#39;oldlocals&#39;,)))<br>&gt;&gt;&gt; newly_defined<br>set([&#39;a&#39;, &#39;c&#39;, &#39;b&#39;, &#39;d&#39;])<br>&gt;&gt;&gt; a,b,c,d<br>
(1, 2, 3, 4)<br>&gt;&gt;&gt; for var in newly_defined: del(locals()[var])<br>...<br>&gt;&gt;&gt; a,b,c,d<br>Traceback (most recent call last):<br>&nbsp; File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>NameError: name &#39;a&#39; is not defined<br>
&gt;&gt;&gt;<br><br></p><br><div class="gmail_quote">2008/10/25  <span dir="ltr">&lt;<a href="mailto:michele@nectarine.it" target="_blank">michele@nectarine.it</a>&gt;</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>
 &nbsp;del i<br>
<br>
Mi sembrava ragionevole e così l&#39;ho fatto girare:<br>
&gt;&gt;&gt; dir()<br>
[&#39;__builtins__&#39;, &#39;__doc__&#39;, &#39;__name__&#39;, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;random&#39;]<br>
&gt;&gt;&gt; for i in dir()[:]:<br>
... &nbsp; &nbsp; del i<br>
...<br>
&gt;&gt;&gt; dir()<br>
[&#39;__builtins__&#39;, &#39;__doc__&#39;, &#39;__name__&#39;, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;random&#39;]<br>
&gt;&gt;&gt;<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>