class - Returning a specific data type when referring to an object in Python -
usually when outputting object in python, define string returned in __repr__, if want return else instead, integer or tuple?
i'll give example. class users , there member variables self.username , self.email. if want output object of type users, how return (self.username,self.email) tuple?
you can't. return value __repr__ must string, , content of string should represent valid python expression can passed eval() create new object of type if possible.
https://docs.python.org/2/reference/datamodel.html#object.repr
Comments
Post a Comment