Concerning classes (Newb question)

  • Thread starter Cyrille Lavigne
  • Start date
C

Cyrille Lavigne

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
 
E

Erik Max Francis

Cyrille said:
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()
 
T

Terry Reedy

Cyrille Lavigne said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top