Could Python supplant Java?

Delaney, Timothy tdelaney at avaya.com
Thu Aug 22 04:24:21 CEST 2002


> From: Stuart D. Gathman [mailto:stuart at bmsi.com]
> 
> On Wed, 21 Aug 2002 11:25:31 -0400, Mark McEahern wrote:
> 
> > In other words, you don't care whether it's a file, you 
> care whether you
> > can read() it?  That makes sense to me.
> 
> This is exactly what Java interfaces do for you.  If you declare a
> variable as "FileLike", then any object, regardless of 
> derivation, can be
> directly assigned to it provided it implements the FileLike interface.

Yes .. which the File object does not. So you need to wrap it in a FileLike
object.

And of course, every single FileLike object has to (minimally) implement
each method that the original author considers to be "FileLike". Which is
presumably all the methods of the File object.

OTOH, if the need of a method is that the object implements the "read"
method, then a file object will do, or a "file-like" object, or indeed
anything which can be "read" from ... If you want to adapt an object to be
used in the method, you simply need a class which adapts the "read" method
to whatever is appropriate for the wrapped object - nothing else.

Tim Delaney




More information about the Python-list mailing list