def __repr__(self):
return '<%s %s (%s:%s) %s>' % (
self.__class__.__name__, self.urlconf_name, self.app_name,
self.namespace, self.regex.pattern)
What is the significance/purpose of this method?
def __repr__(self):
return '<%s %s (%s:%s) %s>' % (
self.__class__.__name__, self.urlconf_name, self.app_name,
self.namespace, self.regex.pattern)
What is the significance/purpose of this method?
An example to see the differences between them (I copied from this source),
The returns of
repr()
andstr()
are identical forint x
, but there's a difference between the return values forstr
y
-- one is formal and the other is informal. One of the most important differences between the formal and informal representations is that the default implementation of__repr__
for a str value can be called as an argument to eval, and the return value would be a valid string object, like this:If you try to call the return value of
__str__
as an argument to eval, the result won't be valid.