Advanced Topics

To understand what I'm going to talk about here, you should have some Java background and have read the API documentation for OutputStream.

Overriding write()

Another way to override all of write()'s forms is to override only the abstract version and then just call the others. You can also use a variable number of arguments for write() and then just use the apply() method to execute the nonabstract forms. Let me show you what I mean. (The following code is from Overload.py.)

 class OutputScreen2 (OutputStream): def write(self, *args): # If the args length is greater than one or the first # argument is not type IntType, use the apply method. if len(args) > 1 or not type(args[0]) is types.IntType: # Use the apply method to call ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.