Programmer218 wrote:I do have def indented and stuff srry about that, but i dont think thats wrong now i believe it might be,
...
I dont know which one is wrong or if they both are.
Are you absolutely sure you have two underlines/underscores both sides of the 'init' in the declaration (def)??
This is what I get in my Python 2.7 on Windows:
Code: Select all
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> class Ball:
def __init__(self, canvas, color):
self.canvas = canvas
>>> canvas = 1
>>> ball = Ball(canvas, 'red')
>>>
...so works fine (note that I just used a dummy value for canvas to keep it simple)!
However, if I use only one underline/underscore:
Code: Select all
>>> class Ball:
def _init_(self, canvas, color):
self.canvas = canvas
>>> ball = Ball(canvas, 'red')
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
ball = Ball(canvas, 'red')
TypeError: this constructor takes no arguments
>>>
Personally I think the requirement for double underscore is the most annoying thing I have come against in Python so far - utterly confusing as most typefaces do not separate the underscores, so hard to realise when looking at example code
