Skip to main content
added missing cls parameter
Source Link
Eli Courtwright
  • 194.5k
  • 69
  • 224
  • 257

It sounds like you want a static method:

class class1(object):
    @staticmethod
    def parse(array):
        ...

Note that in such cases you leave off the usually-required self parameter, because parse is not a function called on a particular instance of class1.

On the other hand, if you want a method which is still tied to its owner class, you can write a class method, where the first argument is actually the class object:

class class1(object):
    @classmethod
    def parse(cls, array):
        ...

It sounds like you want a static method:

class class1(object):
    @staticmethod
    def parse(array):
        ...

Note that in such cases you leave off the usually-required self parameter, because parse is not a function called on a particular instance of class1.

On the other hand, if you want a method which is still tied to its owner class, you can write a class method, where the first argument is actually the class object:

class class1(object):
    @classmethod
    def parse(array):
        ...

It sounds like you want a static method:

class class1(object):
    @staticmethod
    def parse(array):
        ...

Note that in such cases you leave off the usually-required self parameter, because parse is not a function called on a particular instance of class1.

On the other hand, if you want a method which is still tied to its owner class, you can write a class method, where the first argument is actually the class object:

class class1(object):
    @classmethod
    def parse(cls, array):
        ...
Source Link
Eli Courtwright
  • 194.5k
  • 69
  • 224
  • 257

It sounds like you want a static method:

class class1(object):
    @staticmethod
    def parse(array):
        ...

Note that in such cases you leave off the usually-required self parameter, because parse is not a function called on a particular instance of class1.

On the other hand, if you want a method which is still tied to its owner class, you can write a class method, where the first argument is actually the class object:

class class1(object):
    @classmethod
    def parse(array):
        ...