我是 Python 新手,正在尝试通过创建通讯录来进行实验。我怀疑 displayPerson 函数有问题。我不能同时返回多个变量吗?
def lowercasewrapper(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs).lower()
return wrapper
#Class with object attributes
class People():
numofpeeps = 0
listofpeeps = []
def __init__(self, name, age, phone, fblink):
self.name=name
self.age=age
self.phone=phone
self.fblink=fblink
People.numofpeeps += 1
People.listofpeeps.append(self.age)
@lowercasewrapper #calling the wrapper, to make all strings lowercase
def displayPerson(self):
return self.name, self.age, self.phone, self.fblink
george=People("gEORge", "5", "503-405-4021", "http://facebook.com/boobs")
dave=People("dave", "10", "971-863-3905", "http://boobs.com")
charlie=People("CHARLIE", "19", "823-405-2942", "http://boobs.com")
print george.displayPerson()
print "Total number of people: ", People.numofpeeps
print "List of ages: ", People.listofpeeps
error shows the following: File "example.py", line 54, in <module>
print george.displayPerson()
File "example.py", line 31, in wrapper
return func(*args, **kwargs).lower()
AttributeError: 'tuple' object has no attribute 'lower'