object.enable() anti-pattern
Terry Jan Reedy
tjreedy at udel.edu
Thu May 9 02:41:56 EDT 2013
On 5/9/2013 1:23 AM, Steven D'Aprano wrote:
> Besides, this is not to denigrate the idea of a read() function that
> takes a filename and returns its contents. But that is not an object
> constructor. It may construct a file object internally, but it doesn't
> return the file object, so it is completely unrelated to the scenario I
> described.
At least a few stdlib modules that define classes *also* have such
functions. They create an instance of the class, call one or more
methods, and return the result of the method, discarding the instance.
For instance, see the subprocess module, its POpen class, and module
functions; or the timeit module, its Timer class, and functions.
More information about the Python-list
mailing list