View Single Post
Old 04-29-2004, 07:17 AM   #1 (permalink)
MealMan401
Registered User
 
MealMan401's Avatar
 
Join Date: Apr 2004
Posts: 10
MealMan401 is on a distinguished road
Python class definitions

Hi,

Just started playing around in Python. Copied out a example off of Sourceforge and it didn't work (after writing my own class and that didn't work either ). Neither did any other examples, so maybe i am missing something that is a assumed in the examples

THis is what i wrote in the interpreter (WIndows version of the IDLE Python 2.3)
Code:
first try:


>>> class SimpleClass:
	def _init_(self):
		self.data = 3
	def get(self):
		print self.data

	
>>> m = SimpleClass()
>>> m.get()

Traceback (most recent call last):
  File "<pyshell#12>", line 1, in -toplevel-
    m.get()
  File "<pyshell#10>", line 5, in get
    print self.data
AttributeError: SimpleClass instance has no attribute 'data'



and second try:


>>> class SimpleClass:
	def _init_(self, init_val):
		self.data = init_val
	def get(self):
		print self.data

>>> m = SimpleClass(1)

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in -toplevel-
    m = SimpleClass(1)
TypeError: this constructor takes no arguments






anyone know why its not working???

Thanks
MealMan401 is offline   Reply With Quote