New submission from avraf: import re
__no_spaces_pattern = r'\S+' __match_chars_until_space = re.compile(__no_spaces_pattern).match __match_chars_from_last_space = re.compile(__no_spaces_pattern + '$').match def __get_chars_until_space(name): return __match_chars_until_space(name).group() def __get_chars_from_last_space(name): return __match_chars_from_last_space(name).group() __random_unique_five_digit_number = 12345 __random_id_generator = lambda: __random_unique_five_digit_number class Person(object): def __init__(self, name): self.name = name @property def first_name(self): return __get_chars_until_space(self.name) @property def last_name(self): return __get_chars_from_last_space(self.name) I get this error when importing and running in another file. It seems python mangles every occurrence of double underscores seen in a class. Even if the double underscores variable appears in the body of a method and belongs to the module. This behavior is very unexpected. Traceback (most recent call last): File "beef.py", line 5, in <module> print bob.first_name File "/home/dude/style/static_private_methods/real_static_private_functions.py", line 22, in first_name return __get_chars_until_space(self.name) NameError: global name '_Person__get_chars_until_space' is not defined ---------- messages: 273023 nosy: avraf priority: normal severity: normal status: open title: Double underscore variables in module are mangled when used in class type: behavior versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27793> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com