Newbie needs "interface"

Richard Brodie R.Brodie at rl.ac.uk
Thu Nov 22 11:57:30 EST 2001


"Roberto Bonato" <rbonato at irisa.fr> wrote in message news:3BFD2536.7B4AFFC6 at irisa.fr...

> Sometimes I want the results to be written on the stdout,
> sometimes on a Tkinter Text widget, sometimes to a file. I feel the need
> of something like a Java Interface with a method "write" to wrap all
> such devices into.

A Java interface is a 'promise' to implement a method. In Python, just
make classes with a write method.

Trivial example:

class T:
    def write(self, input):
        sys.stdout.write('DEBUG-->' + input)

t = T()
print >> t, (1,2),

DEBUG-->(1, 2)







More information about the Python-list mailing list