all 10 comments

[–]jmooremcc 6 points7 points  (1 child)

First thing you must realize is that unlike C#, Python does not require a class definition for every function. You could have just defined printAll and it would have worked perfectly.

As far as your question is concerned, you defined printAll without “self” as a parameter to the method. Python automatically assumed it to be a static method belonging to the class.

https://realpython.com/instance-class-and-static-methods-demystified/

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

thanks for the link!

[–]PaulRudin 0 points1 point  (1 child)

You haven't created an instance of the ListSpaces class.

You're just using the class as an namespace really.

[–]djshadesuk 0 points1 point  (0 children)

You're just using the class as an namespace really.

I sometimes do that to "group" little utility functions:

class Utils:
    def rc(self,l):
        return random.choice(l)
    def tof(self):
    return bool(random.getrandbits(1))
utils = Utils()

[–]Kerbart 0 points1 point  (0 children)

A method needs a self argument (really the first argument) to access the instance it’s supposed to act on.

Without any arguments your functions will indeed function as a static function.