Forward References?
Jerome Chan
eviltofu at rocketmail.com
Tue Apr 18 07:36:11 EDT 2000
In article <m3itxgcggc.fsf at atrus.jesus.cam.ac.uk>, Michael Hudson
<mwh21 at cam.ac.uk> wrote:
> Jerome Chan <eviltofu at rocketmail.com> writes:
>
> > Just a silly question but how do I do forward references?
> >
> >
> > class a:
> > def x(self):
> > y(self)
> > def y(self):
> > print "Hello"
> >
> > c = a()
> > c.x()
> > c.y()
> >
> > gives a NameError: y
>
> Your mistake isn;t what you think it is, try this instead:
>
> class a:
> def x(self):
> self.y()
> def y(self):
> print "Hello"
>
> HTH, HAND,
> M.
Thanks! I also found out that
a.y() works!
More information about the Python-list
mailing list