Last active
December 29, 2015 11:41
-
-
Save sirkonst/6eff694c4546700417ea to your computer and use it in GitHub Desktop.
How to get segmentation fault with crazy __ (python 2 and 3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__obj = object() | |
# uncomment for fix: | |
# _Class__obj = __obj | |
def func(): | |
print('func:', __obj) | |
class Class: | |
def class_func(self): | |
# uncomment for get !!SEGMENTATION FAULT!!: | |
# nonlocal __obj | |
print('class_func:', __obj) | |
print('---') | |
func() | |
# OK: | |
# -> func: <object object at 0x7f515eccf070> | |
print('---') | |
c = Class() | |
c.class_func() | |
# WTF??>: | |
# -> NameError: name '_Class__obj' is not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references: