Python: Define a static function in a class

Most functions in a class will refer to a "self" instance.

If you want a static function, you'll have to add the @staticmethod decorator.

class Something(object):
@staticmethod
def get_by_name(name):
return "Hello world"

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog