[Tutor] Basics of Classes
amk at amk.ca
amk at amk.ca
Sun Oct 26 20:57:03 EST 2003
On Mon, Oct 27, 2003 at 09:46:27AM +0900, Harm_Kirchhoff at mail.digital.co.jp wrote:
> >>> class harm:
> def __getitem__(self, index):
> return index ** 2
> >>> a3=harm
> >>> print a3 [2]
You haven't created an instance, only bound the name 'a3' to a class object
that's also bound to the name 'harm'. Try 'a3=harm()' to make an instance
of the class.
Two useful tutorials on how to think about Python objects (not necessarily
just classes):
http://starship.python.net/crew/mwh/hacks/objectthink.html
http://effbot.org/guides/python-objects.htm
--amk
More information about the Tutor
mailing list