Yet another Python textbook
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Nov 22 22:26:37 EST 2012
More information about the Python-list mailing list
Thu Nov 22 22:26:37 EST 2012
- Previous message (by thread): Yet another Python textbook
- Next message (by thread): Yet another Python textbook
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 22 Nov 2012 17:41:22 -0500, Colin J. Williams wrote: > You and I used __format__. I understand that the use of double > underscore functions is deprecated. Double leading and trailing underscore methods are not deprecated, they are very much part of the public interface. But they are reserved for Python's use, and under normal conditions you should not be using them by hand. For example: y = x.__add__(1) # NO y = x + 1 # YES if mylist.__len__() > 2: # NO if len(mylist) > 2: # YES > Is there some regular function which can achieve the same result? The built-in format() function is the public API for calling the dunder method __format__. So normally you would write: format(value, spec) instead of value.__format__(spec). -- Steven
- Previous message (by thread): Yet another Python textbook
- Next message (by thread): Yet another Python textbook
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list