Python can't call module method from staticmethod?

consider the following template:

'''some module body''' def __foo(): '''module method foo''' pass class Dummy(object): @staticmethod def bar(): __foo() __foo() # No Error. Dummy.bar() #NameError: Global name "_Dummy__foo" is not defined. 

Why is this happening?

-

And if it is bad to call it "__", what is the best practice in Python for creating modular methods available only for intra-modular functions / methods?

+4
source share
1 answer

Do not start names with double underscores. Any identifier found in a class instruction, starting with at least two underscores and ending with less than two underscores, gets _Classname , where Classname is the name of the class. This implies limited support for private variables, but using it is often considered bad practice.

+5
source

Source: https://habr.com/ru/post/1489828/


All Articles