I\'m running pylint on some code, and receiving the error \"Too few public methods (0/2)\". What does this message mean? The pylint docs are not helpful:
The error basically says that classes aren't meant to just store data, as you're basically treating the class as a dictionary. Classes should have at least a few methods to operate on the data that they hold.
If your class looks like this:
class MyClass(object):
def __init__(self, foo, bar):
self.foo = foo
self.bar = bar
Consider using a dictionary or a namedtuple
instead. Although if a class seems like the best choice, use it. pylint doesn't always know what's best.
Do note that namedtuple
is immutable and the values assigned on instantiation cannot be modified later.