My Python annoyances
Ben Collver
collver at peak.org
Fri May 4 10:43:33 EDT 2007
Chris Mellon wrote:
> You should "check" for the methods by calling them. If the object
> doesn't support the method in question, you will get a runtime
> exception. Premature inspection of an object is rarely useful and
> often outright harmful.
That makes sense, thank you for the response.
What about the case where I have an array of objects that represent some
particular binary file format. If the object is a file, then I want to
copy its contents. If the object is a string, then I want to write the
string. And so forth.
Should I assume that an object is file-like if it has a read method, and
that I can call the read method without unexpected side effects?
Ben
More information about the Python-list
mailing list