Question

I'm trying to figure out how to print out the instance of a class with user defined attributes in Python 3. Here is the code I have:

class Attendie: 
    def __init__(self, fname, lname, company, state, email):
        self.fname = fname
        self.lname = lname
        self.company = company
        self.state = state
        self.email = email

    def getFname(self):
        return self.fname

    def getLname(self):
        return self.lname

    def getCompany(self):
        return self.company

    def getState(self):
        return self.state

    def getEmail(self):
        return self.email

def main():


    fname = input("what is the attendie's first name? ")
    lname = input("What is the attendie's last name? ")
    company = input("What company is the attendie with? ")
    state = input("What state is the attendie from? ")
    email = input("What is the attendie's email address? ")

    Person = Attendie(fname, lname, company, state, email)

    print(Person.getFname)
    print(Person.getLname)
    print(Person.getCompany)
    print(Person.getState)
    print(Person.getEmail)

if __name__ == '__main__': main()

After I run the program I get these types of error messages.

bound method Attendie.getFname of <main.Attendie object at 0x00000000031DCDD8

Was it helpful?

Solution

It seems that you are not calling the methods.

In [1]: class A(object):
   ...:     def __init__(self, n):
   ...:         self.n = n
   ...:     def get_n(self):
   ...:         return self.n
   ...:     

In [2]: a = A(5)

In [3]: a.get_n
Out[3]: <bound method A.get_n of <__main__.A object at 0xa56516c>>

In [4]: a.get_n()
Out[4]: 5

Changing your code as follows should fix it:

print(Person.getFname())
print(Person.getLname())
print(Person.getCompany())
print(Person.getState())
print(Person.getEmail())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top