Every Python dev falls for this (name mangling)

Don’t fall for it! The Zen of Python must not have been invented yet because this feature is confusing, not obvious, implicit, and much more. Private name mangling in Python converts variable usages like __var into _ClassName__var at compile time and there’s no warning it’s happening until you run into the trap. ― mCoding with James Murphy () Source code: Python docs: CPython mangle: #L542 SUPPORT ME ⭐ --------------------------------------------------- Sign up on Patreon to get your donor role and early access to videos! Feeling generous but don’t have a Patreon? Donate via PayPal! (No sign up needed.) Want to donate crypto? Check out the rest of my supported donations on my website! Top patrons and donors: Jameson, Laura M, Dragos C, Vahnekie, Neel R, Matt R, Johan A, Casey G, Mark M, Mutual Information BE ACTIVE IN MY COMMUNITY 😄 --------------------------------------------------- Discord: Github: Reddit: Facebook: CHAPTERS --------------------------------------------------- 0:00 Unexpected output 2:31 Private name mangling 4:23 Python does not have private variables 4:54 Mangling rules 6:51 Mangling at compile time 8:28 Compiler explorer 10:18 getattr and setattr 10:55 To mangle or not to mangle? 13:53 Thanks
Back to Top