Previous: 3.25.1 Repr Objects Up: 3.25 repr Next: 3.26 new


3.25.2 Subclassing Repr Objects

The use of dynamic dispatching by Repr.repr1() allows subclasses of Repr to add support for additional built-in object types or to modify the handling of types already supported. This example shows how special support for file objects could be added:

import repr
import sys
class MyRepr(repr.Repr):
 def repr_file(self, obj, level):
 if obj.name in ['<stdin>', '<stdout>', '<stderr>']:
 return obj.name
 else:
 return `obj`
aRepr = MyRepr()
print aRepr.repr(sys.stdin) # prints '<stdin>'


Previous: 3.25.1 Repr Objects Up: 3.25 repr Next: 3.26 new
Release 2.2.3, documentation updated on 30 May 2003.
See About this document... for information on suggesting changes.

AltStyle によって変換されたページ (->オリジナル) /