<div dir="ltr">Il giorno 3 novembre 2016 07:26, Giammi <span dir="ltr"><<a href="mailto:glbattistella@tiscali.it" target="_blank">glbattistella@tiscali.it</a>></span> ha scritto:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Buon giorno mi chiamo Battistella Gianmaria . Scusate l'ignoranza ! Sono un principiante Volevo sapere come creare una istanza ad una classe partendo da una stringa, es.<br>
Nomeclasse ='classe'<br>
Istanzaclasse=..<br>
</blockquote></div><br></div><div class="gmail_extra">Puoi usare la built-in getattr, ma ti serve anche un riferimento al modulo dove la classe è definita. :<br><br><div style="margin-left:40px"><font size="2"><span style="font-family:monospace,monospace">import sys<br><br>class MyClass(object):<br></span></font></div></div><div class="gmail_extra" style="margin-left:40px"><font size="2"><span style="font-family:monospace,monospace"> pass<br></span></font></div><div class="gmail_extra" style="margin-left:40px"><font size="2"><span style="font-family:monospace,monospace"><br><br></span></font></div><div class="gmail_extra" style="margin-left:40px"><font size="2"><span style="font-family:monospace,monospace">my_class_module = </span></font><font size="2"><span style="font-family:monospace,monospace">sys.modules[__name__]</span></font></div><div class="gmail_extra" style="margin-left:40px"><font size="2"><span style="font-family:monospace,monospace">my_class_instance = getattr(my_class_module, 'MyClass')()</span></font><br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature"><div dir="ltr"><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">|_|0|_|</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace"></span><div><span style="font-family:monospace,monospace">|_|_|0|<br>|0|0|0|<br><br></span></div></div></div>
</div></div>