1
class human(object):
    kind = 'humam'
    def __init__(self,name, sex, age):
        self.name = name
        self.sex = sex
        self.age = age
    def report(self):
        print(self.name)
        print(self.sex)
        print(self.age)
com = int(input('What would you like to do: \n 1) Add a contact \n 2) Info on a contact \n 3) Break\n'))
while com != 3:
    if com == 1:
        name,sex,age = input('Enter name sex age: ').split()
        name = human(name,sex,age)
    if com == 2:
        name = input('Enter name: ')
        name.report()
    com = int(input('What would you like to do: \n 1) Add a contact \n 2) Info on a contact \n 3) Break\n'))
After defining some Uman objects, I could not access them if not during the same execution, for example, selecting 1 to add contact, once instantiated john = Uman('john','Male','20') When selected 2 to check the information of the object appears the following error: name.report() Attributeerror: 'str' Object has no attribute 'report' How can I fix this?
In fact, the instance does not get the name
john, but yesname. What you are doing is storing only one objecthumanin a variablenamewhen the option is 1, but when it is 2, you store the name of the person inname, making it lose the reference to the object, becoming a string.– Woss