Python Forum
API REST Package for Calling/Flask
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API REST Package for Calling/Flask
#10
(Oct-20-2021, 01:08 PM)muzikman Wrote: This guy is great. So, when designing a class, what things make you consider using name mangling? I am thinking that it mangles the name in order to prevent name collision, maybe? We can still access the variable even after we mangle it?
If look at my last example so do sub-class Bar use same name __var = 3,normally would this override the firs one.
Name mangling is helpful for letting subclasses override methods without breaking intraclass method calls.
Let say a new company say a car is newer than is bye override method year_made.
I have not find to much usage for this yet.
class CarMaker:
    # car_id is not meant to be a part of the public interface
    # So it's a advice that is best to leave it alone
    _car_id = 12345

    def __init__(self, color):
        self.car_color = color

    def year_made(self):
        return 2019

    __year_made = year_made # Private copy of original year_made() method

class NewCompany(CarMaker):
    def year_made(self):
        return 2020
Use:
>>> car = NewCompany('Red')
>>> car.year_made()
2020
>>> # Carmaker still have orginal year made
>>> car._CarMaker__year_made()
2019
(Oct-20-2021, 01:08 PM)muzikman Wrote: I've never heard of the __slots__ dunder. When should it be used?
It's for memory saving and faster attribute access,look at link.

(Oct-20-2021, 01:08 PM)muzikman Wrote: You answer almost all of the questions on this site. You must be a Python master.
No it's just hobby that i used some(or lot time in periods) time over many years.
Reply


Messages In This Thread
API REST Package for Calling/Flask - by muzikman - Oct-16-2021, 06:39 PM
RE: API REST Package for Calling/Flask - by snippsat - Oct-20-2021, 05:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with return on REST API Flask korenron 0 1,338 Jun-13-2021, 10:40 AM
Last Post: korenron
  Calling Oracle REST SQL from Python johnjacob 2 2,079 Nov-05-2020, 04:19 AM
Last Post: johnjacob
  rest api parameter in flask bluefrog 3 3,331 Jun-21-2018, 05:03 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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