Forward References?

Justin Sheehy dworkin at
Tue Apr 18 18:53:14 EDT 2000

"Jeff Massung" <jmassung at> writes:

> >class a:
> >   def x(self):
> >      y(self)

> Should this be a.y(self)?

No, it should be self.y()

It could be a.y(self), and that would work for many cases, but that
isn't really what you want.

> Also, someone mentioned above having: self.y() (or self.y(self)), my
> question is what is the difference between a.y and self.y?

It's easy to find out in the interactive interpreter.

>>> class a:
...  def y(self):
...   print 1
>>> b = a()
>>> a.y
<unbound method a.y>
>>> b.y
<method a.y of a instance at 80a67e8>
>>> b.y()
>>> a.y()
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: unbound method must be called with class instance 1st
>>> a.y(b)

Or, of course, one could read the documentation or tutorial.  This is
pretty well explained, iirc.



More information about the Python-list mailing list