Is it a convention to prefix private classes with underscores?

后端 未结 4 1069
小鲜肉
小鲜肉 2021-01-17 22:35

I have seen code in which functions/constants are prefixed with underscores. My understanding is that this indicates that they are not to be used directly. Can I do this wit

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-17 23:01

    Yes; the single underscore usage is endorsed by PEP8 for internal-use classes.

    I don't believe the double underscore usage will have any real effect most of the time, since it's used to active name mangling for class attributes, and generally a class isn't an attribute of another class (granted, it can be, in which case Python will happily mangle the name for you.)

提交回复
热议问题