<div class="gmail_quote">2012/2/27 Daniele Zambelli <span dir="ltr"><<a href="mailto:daniele.zambelli@gmail.com">daniele.zambelli@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Cioè vorrei ottenere la lista dell classi contenute in un modulo.<br>Scusate per la lunghezza e grazie dell'attenzione.<br></blockquote><div><br></div><div>Con un file c.py fatto così:</div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div class="gmail_quote"><div><div><font face="'courier new', monospace">class X:</font></div></div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace"> pass</font></div></div>
</div><div class="gmail_quote"><div><div><font face="'courier new', monospace"><br></font></div></div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace">class Y:</font></div></div>
</div><div class="gmail_quote"><div><div><font face="'courier new', monospace"> pass</font></div></div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace"><br></font></div></div>
</div><div class="gmail_quote"><div><div><font face="'courier new', monospace">Z = {}</font></div></div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace"><br></font></div></div>
</div><div class="gmail_quote"><div><div><font face="'courier new', monospace">W = 3</font></div></div></div></blockquote><div class="gmail_quote"><div><br></div><div>Con questo codice:</div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">
<div class="gmail_quote"><div><font face="'courier new', monospace">import c</font></div></div><div class="gmail_quote"><div><font face="'courier new', monospace">from types import ClassType</font></div></div>
<div class="gmail_quote"><div><div><font face="'courier new', monospace">for name in dir(c):</font></div></div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace"> if type(getattr(c, name)) == ClassType:</font></div>
</div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace"> print name</font></div></div></div></blockquote><div class="gmail_quote"><div><br></div><div>Ottieni questo output:</div>
</div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_quote"><div><div><font face="'courier new', monospace">X</font></div></div></div><div class="gmail_quote"><div><div><font face="'courier new', monospace">Y</font></div>
</div></div></blockquote><div class="gmail_quote"><div><br></div><div>Va bene?</div><div><br></div><div>Ciao.<br>Marco.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>