(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/module-pycompile.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/module-repr.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/Repr-objects.html| ]]
|
Python Library Reference
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/contents.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/modindex.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/genindex.html| ]]
|
Next: 3.25 py_compile Up: 3.24 repr Previous: 3.24.1 Repr Objects
3.24.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>'
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/module-pycompile.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/module-repr.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/Repr-objects.html| ]]
|
Python Library Reference
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/contents.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/modindex.html| ]]
|
[[yurttas/PL/SL/python/docs/core-python-programming/doc/152/lib/genindex.html| ]]
|
Next: 3.25 py_compile Up: 3.24 repr Previous: 3.24.1 Repr Objects
Send comments on this document to python-docs@python.org.