Relative Content

Tag Archive for pythonclass

Why couldn’t a function of a class use the class variable directly in python?

class IO: supported_srcs = [‘console’, ‘file’] def hidden_func(): supported_srcs.append(‘internet’) hidden_func() print(supported_srcs) It raises NameError: : name ‘supported_srcs’ is not defined I’m trying to use a hidden function in class, but the function couldn’t access the local variable of that class. Isn’t the scope of the class enclosing to the function? My understanding is that Python […]

Python type and object implementations [duplicate]

This question already has answers here: Can’t set attributes on instance of “object” class (7 answers) Finding the source code for built-in Python functions? (8 answers) Closed 4 mins ago. Recently i accidentally saw a strange behaviour of Python: The object class, which is inherited implicitly, doesn’t have a __dict__. But every inherited class, even […]