🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #27226

Re: class A: print A

#27226
From: Rob Wolfe
Date: Tue, 19 Jan 2010 11:44
53 lines
3070 bytes

tikan napisał(a):
> On 18 Sty, 22:43, Łukasz Rekucki <lreku...@gmail.com> wrote:
> > On Jan 18, 8:24 pm, tikan <tik...@gmail.com> wrote:
> >
> > > Witam
> >
> > > class A:
> > >     print A
> >
> > > Traceback (most recent call last):
> > >   File "<stdin>", line 1, in <module>
> > >   File "<stdin>", line 2, in A
> > > NameError: name 'A' is not defined
> >
> > > Jak wyjaśnić takie zachowanie interpretera?
> >
> > Tym, że w trakcie wykonywania ciała klasy A, jeszcze jej nie ma. Więc
> > skoro w aktualnym bloku nie ma nazwy "A" i w aktualnym module też nie
> > ma nazwy "A", to znaczy, że jej nie ma. Co się spodziewałeś uzyskać ?
> >
> >
> >
> >
> >
> > > Pozdrawiam
> > > Krzysztof Chmiel
>
> Spodziewałem się, że nazwa klasy jest wpisywana do słownika modułu w
> linijce class A:
> Problem wziął się stąd, że chciałem utworzyć dekorator do metody klasy
> przyjmujący obiekt klasy jako argument
> class A:
>     @my_decorator(A)
>     def f(self):
>         pass
> Ale jak widać nie działa to tak. Może i słusznie, bo w momencie
> wywoływania dekoratora nie byłyby znane wszystkie atrybuty klasy i
> działanie kodu
> byłoby zależne od kolejności definicji funkcji w klasie.

Musisz jeszcze raz bardzo uwaznie przeczytac ten opis:
http://docs.python.org/reference/executionmodel.html

I zrozumiec, ze "class" (podobnie jak "def") jest wykonywalna
instrukcja,
ktora tworzy dowiazanie do bloku kodu,
ktory z kolei jest wykonywany jako calosc.

http://docs.python.org/reference/compound_stmts.html#class-definitions

RW
Technical Details
Message-ID: <6d11c35b-c893-4272-8ef9-3b3416435ce1@s31g2000yqs.googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!lublin.pl!uw.edu.pl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!postnews.google.com!s31g2000yqs.googlegroups.com!not-for-mail
References: <2c102a9d-5722-4565-8562-346d08ec395d@34g2000yqp.googlegroups.com> <eb25832e-a736-4163-b0ef-de2fafe611b5@k17g2000yqh.googlegroups.com> <ac53f534-6955-4df7-a405-ae545c0fb8c6@h2g2000yqj.googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!lublin.pl!uw.edu.pl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!feeder.news-service.com!postnews.google.com!s31g2000yqs.googlegroups.com!not-for-mail
From: Rob Wolfe <rw@smsnet.pl>
Newsgroups: pl.comp.lang.python
Subject: Re: class A: print A
Date: Tue, 19 Jan 2010 03:44:07 -0800 (PST)
Organization: http://groups.google.com
Lines: 58
Message-ID: <6d11c35b-c893-4272-8ef9-3b3416435ce1@s31g2000yqs.googlegroups.com>
References: <2c102a9d-5722-4565-8562-346d08ec395d@34g2000yqp.googlegroups.com>  <eb25832e-a736-4163-b0ef-de2fafe611b5@k17g2000yqh.googlegroups.com>  <ac53f534-6955-4df7-a405-ae545c0fb8c6@h2g2000yqj.googlegroups.com>
NNTP-Posting-Host: 194.197.79.18
Mime-Version: 1.0
X-Trace: posting.google.com 1263901448 837 127.0.0.1 (19 Jan 2010 11:44:08 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 19 Jan 2010 11:44:08 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: s31g2000yqs.googlegroups.com; posting-host=194.197.79.18;  posting-account=Kl85yQoAAACAhtXaf_cPVYWRBT7UPb10
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)  AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0,gzip(gfe),gzip(gfe)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit