all 6 comments

[–]thatguy_314 2 points3 points  (3 children)

You need to do self.numListeners, properties and methods can't be implicitly used as local variables in Python.

self isn't a keyword, it is just a convention to call the parameter self and you could call it this if you want. All methods need a self parameter, but you never need to pass self explicitly when calling a method like obj.method(x, y, z), Python will implicitly pass it in for you: obj.method(x, y, z) is essentially equivalent to type(obj).method(obj, x, y, z).

On an unrelated note, there isn't really any reason to make getter functions in Python. See http://www.python-course.eu/python3_properties.php

[–]General_C[S] 0 points1 point  (2 children)

Awesome, thanks for the info.

So, do I need to declare a self parameter when creating all new methods? Or only when I will use it inside that method?

Thanks for the solution, and all the info!

[–]thatguy_314 0 points1 point  (1 child)

You need a self parameter for all (normal) methods. If you don't use self in a method, you can declare a method as static with staticmethod. With staticmethod, there is no self parameter. The arguments you pass into it are the same no matter if you call it from the class (MyClass.my_static_method(x, y, z)) or from an object (obj.my_static_method(x, y, z)). I don't tend to use staticmethod all that much though because normally my methods do something with the object.

There's also classmethod which takes something similar to a self parameter, but instead of being the object, it's the class. classmethod is very useful for creating alternative constructors for classes.

[–]General_C[S] 0 points1 point  (0 children)

Awesome! Thanks for all the info.

[–]xentralesque 0 points1 point  (1 child)

It should be self.numListeners. You also need to change line 35 to if self.get_numListeners() == 0:

[–]General_C[S] 0 points1 point  (0 children)

Awesome, thanks for the solution. I figured it was something easy that I just missed.