Path: csiph.com!news.fcku.it!bofh.it!tornado.fastwebnet.it!53ab2750!not-for-mail Subject: Re: Classi References: <47Kgz.47242$pt.15731@tornado.fastwebnet.it> Newsgroups: it.comp.lang.python From: Smith Message-ID: <57893477.4050405@smith.it> User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Lines: 41 Date: Fri, 15 Jul 2016 21:07:35 +0200 NNTP-Posting-Host: 93.34.176.20 X-Complaints-To: newsmaster@fastweb.it X-Trace: tornado.fastwebnet.it 1468609655 93.34.176.20 (Fri, 15 Jul 2016 21:07:35 CEST) NNTP-Posting-Date: Fri, 15 Jul 2016 21:07:35 CEST Xref: csiph.com it.comp.lang.python:7676 On 13/07/2016 11:52, Riccardo Lemmi wrote: > Smith wrote: > >> Ciao a tutti, >> perchè questo script mi restituisce il messaggio d'errore: >> >> AttributeError: 'NoneType' object has no attribute 'moo' >> >> Mentre dovrei ottenere : >> >> 'python3.4' >> >> Mi potete aiutare? >> Grazie >> >> >> def foo(): >> a = 'python3.4' >> >> class Foo: >> def moo(): >> print(a) >> return Foo >> F = foo() >> F.moo() > > foo non ritorna nulla quindi ad F è assegnato un None. > Diciamo che potresti aggiungere: > > return Foo() > > ma dipende da cosa vuoi ottenere, inoltre la definizione del metodo moo > è errata, deve essere almeno: > > def moo(self): > > ma anche qui potrebbe dipendere da cosa vuoi ottenere (@staticmethod?). > > > Grazie