While coding a new class with the spyder IDE, and using pylint to check the final result, I've ran into error messages (but the code work as expected without error).
Context: in the constructor function, I want to create new members (quite a lot). Usually, these are few enough so I use this coding:
class MyClass():
def __init__(self):
self.a = ...
self.b = ...
But in a case of many members (let's say 10), with all set to the same initial value (let's say they are all dict()), I was tempted to do that:
class MyClass():
def __init__(self):
_vars = ["a", "b", "c", ...]
for _var in _vars:
self.__dict__[_var] = dict()
Further in the class, I was refering to a member using:
class MyClass():
def my_method(self):
print self.c
Error with pylint (in spyder):
When using pylint on this file, I've got an error message saying:
MyClass.my_method: instance of 'MyClass' has no 'c'member.
However, the code runs just fine, without error, ie. I may access the member 'c' without any problem.
Question: is this a proper coding, or should I avoid such a method to initialize members?