April 2014
Beginner to intermediate
634 pages
15h 22m
English
The __format__() method is used by string.format() as well as the format() built-in function. Both of these interfaces are used to get presentable string versions of a given object.
The following are the two ways in which arguments will be presented to __format__():
someobject.__format__(""): This happens when the application does format(someobject) or something equivalent to "{0}".format(someobject). In these cases, a zero-length string specification was provided. This should produce a default format.someobject.__format__(specification): This happens when the application does format(someobject, specification) or something equivalent to "{0:specification}".format(someobject).Note that something equivalent to "{0!r}".format() ...