[Tutor] Class

Magnus Lyckå magnus@thinkware.se
Tue Jun 17 07:34:23 2003


First of all, you need to indent the method definitions to
tell Python that they are part of the class. As you notice
if you actually try to run the code you posted, you will get
an indentation error.

Secondly, all methods needs self, i.e. the instance object,
as it's first parameter. You missed that in "addEntry" (if
you mean for it to be a part of the class).

Thirdly, we aren't mindreaders, so we can hardly tell you
what it is that you want next. ;) Even if we could, it's
probably better if you figure out how to do it without too
much help. How would you do it without using a class?

I suggest that you read some tutorial that covers classes.
See http://www.python.org/doc/Newbies.html for a wide selection
of tutorials. Maybe Alan's is good for you? See:
http://www.freenetpages.co.uk/hp/alan.gauld/ and click on
"Object Oriented Programming" in the menu. (It's under
"Advanced Topics".

At 00:42 2003-06-17 -0700, Darren Teo wrote:
>hey i was wondering how do you write a class ??
>
>class Diary:
>
>def __init__(self):
>    self.data = []
>
>def addEntry(day, month, year, text):
>
>i am not sure what to write in here . this methods adds an entry for the 
>date(day, month, year). Thanks.
>
>
>Do you Yahoo!?
><http://pa.yahoo.com/*http://rd.yahoo.com/evt=1207/*http://promo.yahoo.com/sbc/>SBC 
>Yahoo! DSL - Now only $29.95 per month!

--
Magnus Lycka (It's really Lyck&aring;), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language