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
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
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
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
>
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.