Re:I'm Switching to Python and Actually Liking It
by freehorse on Wednesday July 16, 2025 @11:36AM
(#44583464)
There are private and public methods. Private methods are only supposed to be called within other methods, as in privately. Public methods are the ones that are normally called through the code, repl, by the user or whatever. You are not supposed to write `myclass.__add__(x)` anywhere except where you define the class itself and its methods.
[ Parent
| on HN ]
Re:I'm Switching to Python and Actually Liking It
by Izkata on Wednesday July 16, 2025 @12:36PM
(#44584257)
There's actually 4 kinds:
def foo(... # public
def _foo(... # internal
def __foo(... # munged
def __foo__(... # magic
Internal is more convention as the language doesn't really do anything with it, but it does with munged, and magic methods are specifically for things implemented in the language.Internal and munged don't exactly map to private and protected, but are kinda similar ish.
Re:I'm Switching to Python and Actually Liking It
by freehorse on Wednesday July 16, 2025 @01:50PM
(#44585040)
Oh right. I am not really into python, had read some doc about naming conventions some poitns.
In any case I actually like how one can use underscores to point on how exposed some method is supposed to be. Makes it simpler to actually know what to skip and what not.