A
Andrew Henshaw
Yesterday, I was writing some test code for a module and I wanted some
line-oriented text to use as a data source. I thought about using a
docstring from one of the standard modules; but, it occurred to me that the
Zen of Python text from the 'this' module would be *much* better, as it is
more readable and would be a nice thing for our students to see.
Unfortunately, the actual text is difficult to use:
o the text is ROT-13 encoded and the module's translation routine is
inline
o the text is printed to stdout on import. I understand why Tim did this,
but it did interfere with my purpose.
So, in order to use the module for my test code, I had to implement a short
ROT-13 translator, import the sys module, redirect stdout to a simple
object that provided a null write method, import this, restore stdout, and
then rot13(this.s).
I suggest that the 'this' module could be used to provide a standard,
line-oriented, test text. I would like to see the unencoded text made
available directly, e.g. this.zen().
Unfortunately, my suggestion has a snag. I can't think of a convenient way
to provide the 'import this' functionality for which the module was
oringinally created, without forcing the test programmer to go through the
gyrations of redirecting stdout. We could do an indirect import from
another module that provides the desired behavior; but, this seems like
overkill. Any thoughts?
line-oriented text to use as a data source. I thought about using a
docstring from one of the standard modules; but, it occurred to me that the
Zen of Python text from the 'this' module would be *much* better, as it is
more readable and would be a nice thing for our students to see.
Unfortunately, the actual text is difficult to use:
o the text is ROT-13 encoded and the module's translation routine is
inline
o the text is printed to stdout on import. I understand why Tim did this,
but it did interfere with my purpose.
So, in order to use the module for my test code, I had to implement a short
ROT-13 translator, import the sys module, redirect stdout to a simple
object that provided a null write method, import this, restore stdout, and
then rot13(this.s).
I suggest that the 'this' module could be used to provide a standard,
line-oriented, test text. I would like to see the unencoded text made
available directly, e.g. this.zen().
Unfortunately, my suggestion has a snag. I can't think of a convenient way
to provide the 'import this' functionality for which the module was
oringinally created, without forcing the test programmer to go through the
gyrations of redirecting stdout. We could do an indirect import from
another module that provides the desired behavior; but, this seems like
overkill. Any thoughts?