This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author avraf
Recipients avraf
Date 2016-08-18.12:27:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471523246.01.0.475585276103.issue27793@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2016-08-18 12:27:26avrafsetrecipients: + avraf
2016-08-18 12:27:26avrafsetmessageid: <1471523246.01.0.475585276103.issue27793@psf.upfronthosting.co.za>
2016-08-18 12:27:25avraflinkissue27793 messages
2016-08-18 12:27:25avrafcreate