Jan-21-2019, 03:21 AM
(This post was last modified: Jan-21-2019, 03:34 AM by Pythonhelp82.)
(Jan-20-2019, 02:18 PM)DeaD_EyE Wrote: This should work.
class JuniorMember(Member): def __init__(self, MemberName, MemberID, SubscriptionPaid): super().__init__(MemberName, MemberID, SubscriptionPaid) self.DateOfBirth = ""PS: I forgot to hit the post button :-/
I remember trying that too and it resulted in the same error:
TypeError: __init__() missing 3 required positional arguments: 'MemberName', 'MemberID', and 'SubscriptionPaid'
(Jan-20-2019, 08:33 PM)snippsat Wrote: It's Java written in Python,it's not your fault we see this often in education when have teacher that's come from a Java/C++ background.
Just to show how it could be written in more pythonic way.
Remove getters/setters and__
(is not private,it's name mangling that's not needed here), PEP-8![]()
class Member() : def __init__(self, member_name, member_id, subscription_paid): self.member_name = member_name self.member_id = member_id self.subscription_paid = subscription_paid class JuniorMember (Member): def __init__(self,member_name, member_id, subscription_paid, date_of_birth): super().__init__(member_name, member_id, subscription_paid) self.date_of_birth = date_of_birthTest usage:
>>> new_member = JuniorMember('Ali', 12345, True, "12/11/2001") >>> new_member.member_name 'Ali' >>> new_member.date_of_birth '12/11/2001'. >>> an_other_member = JuniorMember('Tom', 4444, True, "1/2/2018") >>> an_other_member.member_id 4444 >>> an_other_member.subscription_paid True >>> regular_member = Member('Kent', 9999, True) >>> regular_member.member_name 'Kent'But i don't want to give all data at once,use getters/setter?
No it's simple attribute access,have to prove that need more that,if need more@property
can be used.
Use default arguments.
def __init__(self,member_name='', member_id='', subscription_paid='', date_of_birth=''):>>> new_member = JuniorMember() >>> new_member.date_of_birth = '12/11/2001' >>> new_member.date_of_birth '12/11/2001'
This is a fantastic break down and very useful for a beginner and something I will be using definitely, however, I think the purpose of the task is to demonstrate set methods:
• SetMemberName
• SetMemberID
• SetSubscriptionPaid

