#🔒 class methods
46 messages · Page 1 of 1 (latest)
@timber osprey
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
what does "protected" mean?
they probably mean protected in the Java sense where it is private outside but accessible by subclasses
then: no.
like i know i can do it with attributes like self._name
There is no real way to do this. what you're doing there can be accessed everywhere, but you might have auto checkers yell at you
Python has nothing like "private" in the Java sense.
My favorite advice on the topic of method visibility (i.e. public vs. private) comes from Python creator Guido van Rossum. It goes something like “we’re all adults here” and says it’s not really a necessary thing for compilers/runtimes to hide methods from specific callers. Don’t go mucking around in other object’s implementations. I still think...
python uses single underscores for this
you can do self.__private_name but all that does is expand it to self.__ClassName__private_name iirc
thats name mangling
thats different
i dont wanna make it private i wanna make it protected
python doesn't have privste methods, they can all be accessed in one way or another.
Python doesn't have the concept of "protected" or even "private" really like other languages have.
It's all just conventions.
Yeah I’m talking about the conventions
I was having trouble naming a method with a trailing underscore so I was wondering if I was doing something wrong if that just wasn’t possible
Anyone outside of like standard academic institutions just refuses to engage with this topic at all lol
And I get why but it makes it annoying for students forced to learn this
I'll admit, I'm a bit drunk, so I wouldn't go entirely go by my reluctance to give a definite answer. I just don't want to say something stupid and misleading.
😂😂😂
I wish I was drunk too man
But nah it’s not just you
I’ve asked about this before (not specifically about methods)
And it’s always the same thing
“You can’t do that in Python!”
And like, I get it, trust me
But I still have to do this assignment so lol
Theres a clear disconnect between professional python coders and what’s taught in colleges
At least with some things
For a lot of cases, Python is for prototyping. It lets you write code very quickly without thinking about things like access controls. You aren't constained by the language (which can be a good or a bad thing).
If a teacher is trying to map Java concepts to Python, there will be things that won't make a lot of sense.
Unfortunately.
Yeah and I think a lot of my professors come from Java
At the very least not Python I mean they’re all engineers so far
Electrical engineers at that
That is unfortunately pretty typical. Ironically, when I learned Java, my teacher was from a C background and didn't actually know Java. I had to teach myself the basics. Programming has a lot of general ideas, and those ideas don't always map nicely to how different languages work.
Sorry, but I'm going offline. Have a good night.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.