Could Python supplant Java?

Peter Hansen peter at
Thu Aug 22 01:03:27 EDT 2002

"Stuart D. Gathman" wrote:
> On Thu, 22 Aug 2002, Delaney, Timothy wrote:
> > > From: Stuart D. Gathman [mailto:stuart at]
> > > 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.
> If you had kept reading, I talk about this.  And mention "signatures" as
> a statically typed solution to this problem.  The compiler creates
> wrapper classes when needed for any object with the specified methods.
> If you only care about a 'read' method, then specify your function arg/
> variable is declared to take a signature with just a read method.  Now
> any object with a read method can be passed.  

Sounds very much like what Python does, without the hassle.  If your
"signature" is "any object with a read method", and you pass in something
without that signature, the routine will raise an AttributeError and 
tell you the "read" attribute is missing.

The best part is that it does all this without you having to waste
time specifying this outside of the function code itself.  Amazing...


More information about the Python-list mailing list