Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
class instances
-
I'm just learning python and oop in particular so I've got some basic questions.
Why doesn't this work:
class Foo:
def init(self, x, y):
self.x = x
self.y = ybar = Foo(42, 7) <------ here i get the error "this constructor takes no arguments"
print bar.x
hmmmmmm....for some reason this post was stripped of indentation
Thanks!
-
I think you need def init(self, x, y):. Looks like you only have 1 underscore on each side of init.
-
@Gcarver is correct. The init method for a class has two underscores on each side.
@snarl_barx - If you want to preserve your indentation, next time start a block of code with <b><PRE></b> and end it with <b></PRE></b> and it will end up looking like this:
<pre>class Foo:
def init(self, x, y):
self.x = x
self.y = y</pre>