Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Riccardo Lemmi Newsgroups: it.comp.lang.python Subject: Re: Classi Followup-To: it.comp.lang.python Date: Wed, 13 Jul 2016 11:52:07 +0200 Organization: Reflab Lines: 41 Message-ID: References: <47Kgz.47242$pt.15731@tornado.fastwebnet.it> NNTP-Posting-Host: RWm5fT/deJVmfeRkITfJEQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.4.8 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com it.comp.lang.python:7675 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?). -- Riccardo Lemmi