3 ms·
You can guard yourself against overriding in the same module this way, too. For name mangling, I think you need to start your variable with underscores, and th
by eru 7y ago
You can guard yourself against overriding in the same module this way, too.
For name mangling, I think you need to start your variable with underscores, and then it won't be accessible for reading outside the module either?
- Sean1708 7y agoFor modules you can access the variable just fine, but for classes you need to use the mangled name: $ cat >foo.py __FOO = 1 class Foo: __FOO = 2 $ cat >bar.py import foo print(foo.__FOO) print(foo.Foo()._Foo__FOO) $ python3 bar.py 1 2
- xapata 7y agoNope, you don't need to start the name with underscores. class Foo: bar = 'public' __bar = bar # stashed