+ 8

Python Strong-Private-Objects

Suppose I have a class, Account, In this class i have, username="XYZ" _balance=12345 __pasw="pass123" We know, the balance and the pasw are hidden objects, so, inorder to get the password (__pasw) outside the class we type, print(_Account__pasw) But as per my requirement, I want to throw an error for accessing a private object. How would I achieve this. The following is my file you may edit it. https://code.sololearn.com/ca20A253A17A/?ref=app Any help is greatly appreciated, Thank You.

29th Apr 2021, 4:51 PM
Arun Bhattacharya
Arun Bhattacharya - avatar
2 Answers
0
You can use @property decorator which ensures your variable is read only. The set method of the @property is only possible if you implement it in your code.
30th Apr 2021, 11:10 PM
Gbadegesin Muhammed
Gbadegesin Muhammed - avatar
0
Gmuhammed🇳🇬 (CHALLENGE ACCEPTED) Could you elaborate or edit the python file above, please...
1st May 2021, 7:37 AM
Arun Bhattacharya
Arun Bhattacharya - avatar