Python name mangling

后端 未结 11 2131
天命终不由人
天命终不由人 2020-11-22 05:31

In other languages, a general guideline that helps produce better code is always make everything as hidden as possible. If in doubt about whether a variable should be privat

11条回答
  •  醉话见心
    2020-11-22 06:08

    First: Why do you want to hide your data? Why is that so important?

    Most of the time you don't really want to do it but you do because others are doing.

    If you really really really don't want people using something, add one underscore in front of it. That's it... Pythonistas know that things with one underscore is not guaranteed to work every time and may change without you knowing.

    That's the way we live and we're okay with that.

    Using two underscores will make your class so bad to subclass that even you will not want to work that way.

提交回复
热议问题