Why Python has no REAL private methods! #shorts

preview_player
Показать описание
Learn why Python has no real private methods!

Get my Free NumPy Handbook:

📓 ML Notebooks available on Patreon:

If you enjoyed this video, please subscribe to the channel:

~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

#Python
Рекомендации по теме
Комментарии
Автор

This does not explain the reason why python has no private methods, in the sense of language design choice, but shows that there are no private methods

alexpaciniat
Автор

Python looks amazing at beginning. But when your dive deeper and deeper, it kinda starts becoming weird

sritimanadak
Автор

I still dont know why python has no real private methods even I watched this short.

safakkoklu
Автор

Python basically says that _We are all consenting adults here_ . Python trusts the programmer knows not to mess around them, but if they still need to do so, it's still possible, and the programmer knows what they are doing.

There is a mail on this very topic and the sentiment here is compared to Perl and how it differs from C++/Java.

"a Perl module would prefer that you stayed out of its living room because you weren't invited, not because it has a shotgun."
-- Master Oogway

aakashmore
Автор

This actually comes in quite handy when writing tests. Good trick

seventeeen
Автор

This is a very very odd world I find myself exploring. Yall are great.

viatori
Автор

Tô be fair, even in Java you can call private methods if you are nosey enough.

renatocustodio
Автор

Sounds like something ill never do lol

skata
Автор

C# has a powerful "System.Reflection", you can do anything with private methods with it
And maybe Java has the same

There is always a way to "hack" it

arandomscguy
Автор

I think this is a far better solution as in e.g. Java where you'd have to use reflection

aboPLZ
Автор

You usually define a private method with a single underscore at the start

knut-olaihelgesen
Автор

What you mean the function itself becomes private too ?!??

mohammedissam
Автор

What is the function of foo() in python..??

yashbanait...
Автор

Wait a sec.... I thought you can still get and set the value of any "private" attribute in a class without getting any errors (it's against convention, but still possible).
Have I been learning from an old resource if that's not the case?

murtadha
Автор

Not a Python programmer here, but I want to praise the intuitivity of two underscores apparently meaning "private"

managMent_
Автор

I can think of a way to do it. Remember that a class can be defined inside a function, and refer to other locals of that function via lexical binding. If the class is returned as the function result, then code outside that class cannot access those locals.

At least, not easily.

lawrencedoliveiro
Автор

And that's why I stopped programming in Python, I'm currently learning C# for a project

hadawardgz
Автор

"this is considered as private method right?" No, wrong to consider it private to begin with. Single underscore for private by convention, double underscore to name mangle, so that subclasses can define a method with the same name, while still letting parent class access it's original method since it's preserved via a name mangle. In a sense, it's like almost saying, go ahead, feel free to redefine in subclasses without worrying about breaking parent functionality.

darrorpsk
Автор

Meanwhile in C: Guess the address and just fucking call it as if nothing is wrong

Meanwhile in C#: reflection go

AvenDonn
Автор

It is even worst, you can access the libraries that a certain object uses without the need of writing the word import. A thing, which combined with f strings, eval, and user input can destroy ANY computer

dimasveliz