469,949 Members | 2,124 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

Concerning classes (Newb question)

Hi!
I'm very new to the art of programming and I just learn OOP
in python. I want to know why the following bit of code crash.
Code:
class Exemple:
def __init__(self):
self.list=[]
self.var1=3

c=Exemple
print c.list, c.var1

Thanks
Jul 18 '05 #1
2 1224
Cyrille Lavigne wrote:
I'm very new to the art of programming and I just learn OOP
in python. I want to know why the following bit of code crash.
Code:
class Exemple:
def __init__(self):
self.list=[]
self.var1=3

c=Exemple
print c.list, c.var1


You're binding c to the class, not an instance. To create a new
instance, call the class:

c = Exemple()

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ Everything's gonna be all right / Everything's gonna be okay
-- Sweetbox
Jul 18 '05 #2

"Cyrille Lavigne" <do*******@caramail.com> wrote in message
news:6c*************************@posting.google.co m...
Hi!
I'm very new to the art of programming and I just learn OOP
in python. I want to know why the following bit of code crash.


In general, questions like this should include the error message and
traceback. The error message usually tells you 'why' (if only you can
understand ;-).

tjr

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by claudel | last post: by
reply views Thread by David E. | last post: by
3 posts views Thread by Antioch | last post: by
3 posts views Thread by Suzanne Vogel | last post: by
3 posts views Thread by Walter | last post: by
3 posts views Thread by claudel | last post: by
7 posts views Thread by alternativa | last post: by
9 posts views Thread by Thomas Ploch | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.