Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is not exactly "black magic", it's fairly well-known and explained directly in the official documentation: http://docs.python.org/tutorial/classes.html#private-variabl....


I think developers coming to Python from other languages (like I am from a heavy Java background) find the auto-creation of "shadow variables" pretty interesting. To someone used to Java, being able to access a private member via its shadow variable is a lot like black magic.

Discovering this for the first time in Python seemed pretty cool to me. I really hope this feeling of magic in working with Python never leaves me. I want to remain amazed.


Coming from C++, this is very similar to what all C++ compilers do internally (i.e. name mangling). Python just opens a possibility to access that "mangled" names directly, which should never be necessary unless you are doing some metaprogramming and need full access to class internals.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: