Classes encapsulate both data, and behavior, so as general rules:
- If you have something only with data, and no methods, it should probably be a
namedtuple, not a class, unless you need to modify that data after creating it.
- If a function accesses instance data, it should be a method.
- If a function accesses no instance data, but does access class data, it should be a
@classmethod.
- If a function accesses neither instance data nor class data, it should be a standalone function, unless there's some really compelling reason to make it a
@staticmethod.
- If a
class only has one method, or one method in addition to __init__(), then you almost certainly can and should rewrite it as a function.
Classes are really easy to abuse, but the temptation to shove everything into a class should really be avoided. You should use them when they make sense, and avoid using them when they don't.