+ 1
Is it a bad practice to use "list" as a class-variable?
Example: class Entity: list = [] def __init__(self): Entity.list.append(self) It shouldn't overwrite anything since the function list belongs to python but not to the class Entity. Is it still a bad practice to do this?
2 Respuestas
+ 1
It does overwrite the function, just not on all scopes. The following program throws a TypeError.
class Entity:
list = []
def __init__(self):
Entity.list.append(self)
print(list("Hello world!"))
It may see harmless at first, but for more complex codes it's a really big deal.
+ 1
Yes