Python Forum
Modifying Class File/ Name-Mangling
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modifying Class File/ Name-Mangling
#5
(Jun-10-2021, 12:45 PM)Gribouillis Wrote: Anyway, it looks like bad Python code with verbose and unnecessary accessor functions where for example properties would be better.
As Gribouillis metion this is bad Python code look like your teacher comes for Java and have not bother all to learn how is done in in Python.
It's a little frustrating as seen this stuff many times before.
So the 41 line can be these 6 lines,dos just the same job.
class Customer:
    def __init__(self, name, date_of_birth, account_num, email):
        self.name = name
        self.date_of_birth = date_of_birth
        self.account_num = account_num
        self.email = email
So start of main would be like this see that short code over work the same.
from Customer import Customer

def main():
    my_customer = Customer("Bob", "12/12/1982", "1090-332", "[email protected]")
    print(f'{my_customer.name} {my_customer.date_of_birth} {my_customer.account_num} {my_customer.email}')

main()
Output:
Bob 12/12/1982 1090-332 [email protected]
Still relevant Python Is Not Java written in 2004.
Look at Getters and setters are evil. don’t write getters and setters.
Reply


Messages In This Thread
Modifying Class File/ Name-Mangling - by CWillis105 - Jun-09-2021, 11:35 PM
RE: Modifying Class File/ Name-Mangling - by snippsat - Jun-11-2021, 06:42 PM

Forum Jump:

User Panel Messages

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