Tutorial by Examples

The special variable __name__ is not set by the user. It is mostly used to check whether or not the module is being run by itself or run because an import was performed. To avoid your module to run certain parts of its code when it gets imported, check if __name__ == '__main__'. Let module_1.py be ...
The special attribute __name__ of a function, class or module is a string containing its name. import os class C: pass def f(x): x += 2 return x print(f) # <function f at 0x029976B0> print(f.__name__) # f print(C) # <class '__main__.C'> print(C.__name__...
When configuring the built-in logging functionality, a common pattern is to create a logger with the __name__ of the current module: logger = logging.getLogger(__name__) This means that the fully-qualified name of the module will appear in the logs, making it easier to see where messages have co...

Page 1 of 1