I have to following exercise:
Implement a class PersonReader supporting the following methods:
input() asks the user for the name and year of birth of a person at shell prompt (using the builtin input function).
str that returns the string "name (year)" (e.g. to be used by the print method when applied to a PersonReader).
And my idea was to do something like this:
class Personreader:
def __init__(self, name, year):
self.name = name
self.year = year
def from_input(x):
return x(input(),input())
def __str__(self):
print(self.name, self.year)
However this gives an error when I try and call Personreader.from_input(x) or Personreader.from_input(). How can implement this user input in my class?