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.