Python Forum
The function of double underscore back and front in a class function name?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The function of double underscore back and front in a class function name?
#10
Not quite. calculate_gas_milage() would try to call a function named calculate_gas_milage and return a result. This would either raise a NameError, or map "efficiency" to the result, not the function. More importantly, python knows that it needs to change instance.method(args) into insance.__class__.method(instance, args) when it is calling an instance method of a class. It would not know to do that if you just stuffed a function in a dictionary.

I'm occasionally tasked with maintaining Python projects that use dictionaries to mimic classes, even though Python always had classes. Let me just say that doing this is a bad idea and leave it at that. Shudder!
Reply


Messages In This Thread
RE: The function of double underscore back and front in a class function name? - by deanhystad - Feb-19-2024, 03:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  front-end js and back-end python 3lnyn0 0 1,012 Jun-03-2022, 08:51 PM
Last Post: 3lnyn0
  TimeOut a function in a class ? Armandito 1 1,691 Apr-25-2022, 04:51 PM
Last Post: Gribouillis
  Calling a class from a function jc4d 5 1,870 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  Exit function from nested function based on user input Turtle 5 2,965 Oct-10-2021, 12:55 AM
Last Post: Turtle
  a function common to methods of a class Skaperen 7 2,684 Oct-04-2021, 07:07 PM
Last Post: Skaperen
  Tuple generator, and function/class syntax quazirfan 3 3,960 Aug-10-2021, 09:32 AM
Last Post: buran
Question Stopping a parent function from a nested function? wallgraffiti 1 3,711 May-02-2021, 12:21 PM
Last Post: Gribouillis
Question exiting the outer function from the inner function banidjamali 3 3,612 Feb-27-2021, 09:47 AM
Last Post: banidjamali
  Struggling for the past hour to define function and call it back godlyredwall 2 2,261 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  Passing argument from top-level function to embedded function JaneTan 2 2,290 Oct-15-2020, 03:50 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020