[Tutor] pure function problem
Jeremy Jones
jemejones at gmail.com
Thu Sep 23 11:36:58 CEST 2010
The problem is that your class definition doesn't do anything to
explicitly set those attributes.
On Thu, Sep 23, 2010 at 4:58 AM, Roelof Wobben <rwobben at hotmail.com> wrote:
<snip>
> class tijd :
> pass
You're not doing any explicit setting of attributes at the class level.
<snip>
> time = tijd()
> time.hour = 20
> time.minutes = 20
> time.seconds = 20
You set them on this instance.
> seconds = 20
> uitkomst = tijd()
But not on this one.
What you probably want to do is something like this:
class tijd(object):
def __init__(self):
self.hour = 20
self.minutes = 20
self.seconds = 20
Or if you prefer to set these when you create the instance, you can
pass in values like this:
class tijd(object):
def __init__(self, hour=20, minutes=20, seconds=20):
self.hour = hour
self.minutes = minutes
self.seconds = seconds
I noticed something odd just a sec ago. You have this:
> uitkomst = tijd()
> uitkomst = increment(time, seconds)
> print uitkomst.minutes, uitkomst.seconds
You're creating a tijd instance, binding uitkomst to it, then
overwriting that instance with what you return from increment().
Anyway, hth.
- jmj
More information about the Tutor
mailing list