Re: [Tutor] Class definition confusion

2012-02-15 Thread Mark Lawrence
On 15/02/2012 18:35, Hugo Arts wrote: [snip] An __init__ might seem like it's special in some way, declaring attributes. But it's not, really, it's just another method that gets passed the object it is called on (that would be "self"). It's only special because it gets called when an object is c

Re: [Tutor] Class definition confusion

2012-02-15 Thread Mark Lawrence
On 15/02/2012 18:14, Sivaram Neelakantan wrote: I was under the impression that you have to define the attributes of the class before using it in an instance. Following the book 'thinking in Python', class Point: ... """pts in 2d space""" ... print Point __main__.Point b = Point() b.x

Re: [Tutor] Class definition confusion

2012-02-15 Thread Sivaram Neelakantan
On Thu, Feb 16 2012,Alan Gauld wrote: [snipped 19 lines] > Python allows instance attributes to be added at runtime. > In general this is a bad idea IMHO, a dictionary would probably > be more appropriate, but there can, very occasionally, be valid > uses for it. Thanks for that, I kept thinkin

Re: [Tutor] Class definition confusion

2012-02-15 Thread Hugo Arts
On Wed, Feb 15, 2012 at 7:14 PM, Sivaram Neelakantan wrote: > > I was under the impression that you have to define the attributes of > the class before using it in an instance.  Following the book > 'thinking in Python', > class Point: > ...     """pts in 2d space""" > ... print Point >

Re: [Tutor] Class definition confusion

2012-02-15 Thread Alan Gauld
On 15/02/12 18:14, Sivaram Neelakantan wrote: I was under the impression that you have to define the attributes of the class before using it in an instance. Only in some languages. Python is not one of those. class Point: ... """pts in 2d space""" ... b = Point() b.x =3 b.y =4 print b.

[Tutor] Class definition confusion

2012-02-15 Thread Sivaram Neelakantan
I was under the impression that you have to define the attributes of the class before using it in an instance. Following the book 'thinking in Python', >>> class Point: ... """pts in 2d space""" ... >>> print Point __main__.Point >>> b = Point() >>> b.x =3 >>> b.y =4 >>> print b.y 4 >>> Why

Re: [Tutor] Class definition...

2009-02-27 Thread wesley chun
>> I am looking for a good tutorial to walk through that really explains class >> definition. > > I assume from that you have been through the basic tutors like mine? >: > OK, I explain self in my OOP tutor topic ( a sub heading under > "Using Classes"), but again if thats not sufficient th

Re: [Tutor] Class definition...

2009-02-27 Thread Spencer Parker
Your tutorial is awesome...thanks again... The biggest confusion I have just had is the self.balance kind of thing. I need to just remember how it is treating each individual statement is all. Remember how everything is basically an object...just wrapping my brain around it for the most part. On

Re: [Tutor] Class definition...

2009-02-26 Thread Alan Gauld
"Spencer Parker" wrote I am looking for a good tutorial to walk through that really explains class definition. This has been one sticking point that always messes me up I assume from that you have been through the basic tutors like mine? Have you tried the deeper material in Dive into Pyt

[Tutor] Class definition...

2009-02-26 Thread Spencer Parker
I am looking for a good tutorial to walk through that really explains class definition. This has been one sticking point that always messes me up for the most part. That and when people use "self". For some reason I just can't grasp what people say. Any good pointers to throw at me? I really w