[Tutor] pure function problem

Roelof Wobben rwobben at hotmail.com
Thu Sep 23 12:15:07 CEST 2010



> Date: Thu, 23 Sep 2010 05:36:58 -0400
> Subject: Re: [Tutor] pure function problem
> From: jemejones at gmail.com
> To: tutor at python.org
> CC: rwobben at hotmail.com
> 
> 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


Correct, 

I try to find a way to solve this error message.

Roelof

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100923/f65182cf/attachment.html>


More information about the Tutor mailing list