Skip to main content
9 events
when toggle format what by license comment
Aug 13, 2022 at 20:29 vote accept Ramza
Aug 13, 2022 at 18:14 comment added OnceAndFutureKing @Ramza not really, for comparison, lots of objects have 'read' methods (files, databases, web requests), and it doesn't normally cause confusion. Different classes sharing names for methods is actually a core part of OO design (but not really as it's done in my example).
Aug 13, 2022 at 17:45 comment added Ramza @OnceAndFutureKing "encrypt and decrypt aren't recursive here, they're calling other methods of other classes that just happen to also be called encrypt and decrypt"... Ok, I see, but wouldn't that be potentially problematic to use the same names?
Aug 13, 2022 at 17:43 comment added OnceAndFutureKing @Ramza encrypt and decrypt aren't recursive here, they're calling other methods of other classes that just happen to also be called encrypt and decrypt.
Aug 13, 2022 at 17:40 comment added OnceAndFutureKing @Ramza Yes, you can just pass the callable based on its original name. The _ at the beginning of password signals that it's 'private', which tells other programmers not to access it directly, and also means that it won't show up in the list of object variables in some settings (like debugging in some IDEs) - which is a good idea for a password.
Aug 13, 2022 at 17:38 comment added Ramza Hi @OnceAndFutureKing and thank you for the response. I do have a few questions. So in Python, I do not need to store a callable inside a variable? I can simply pass the function name into another function by omitting the ()? What is the purpose of adding _ in the following line: self._password = password? Also, I noticed that decrypt() and encrypt() call themselves. I know this means they are recursive but I'm not sure if I fully understand how this works. In general, how does one determine when a function can be written and called recursively?
Aug 13, 2022 at 17:37 comment added OnceAndFutureKing Class methods sure, static methods, no. mail.python.org/pipermail/python-ideas/2016-July/041189.html
Aug 13, 2022 at 17:35 comment added Reinderien This answer is roughly true. But writing staticmethods is very much 'not pythonic' is not. There are plenty of good applications of static and class methods.
Aug 13, 2022 at 16:56 history answered OnceAndFutureKing CC BY-SA 4.0