I have the following code:
class Personne:
def __init__(self, name, age):
self.name = name
self.age = age
def __getitem__(self, *args):
keys = list(*args)
return [self.__dict__[key] for key in keys]
if __name__ == '__main__':
p = Personne('A', 20)
# age = p['age']
# print(age)
# name = p['name']
# print(name)
name, age = p['name', 'age']
print(name, age)
The uncommented part works fine, but the there is a problem in the commented code. How can i achieve the desired behaviour, which is to get attribute values based on arguments (can be one or many) passed to the getitem method.
Thanks.