Message273023
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 |
|
Date |
User |
Action |
Args |
2016-08-18 12:27:26 | avraf | set | recipients:
+ avraf |
2016-08-18 12:27:26 | avraf | set | messageid: <1471523246.01.0.475585276103.issue27793@psf.upfronthosting.co.za> |
2016-08-18 12:27:25 | avraf | link | issue27793 messages |
2016-08-18 12:27:25 | avraf | create | |
|