How to write verbose scripts

Hendrik van Rooyen mail at microcorp.co.za
Wed Sep 3 16:34:50 EDT 2008


Steven D'Aprano <stev...bersource.com.au> wrote:

>Is there a better way of doing this than the way I am going about it?

Not sure if its "better", but I would keep the messages in a table or dict and
have different tables or dicts for different levels of verbosity, and write a
displayer that knows about the verbosity - This approach has the advantage that
you can write in English and have different verbosities in different languages
too, if the displayer knows about the language.

Verbosity level and language can be display class attributes, and then you can
simply write something like:

display.display("squawk")

and get one of:

 squawk
 squawk, squawk, squawk
 squawk - help the bastards are trying to nail me to my perch!

or the equivalent in Icelandic or Norwegian.

It works, but its a PITA to implement because you have to formally construct the
stuff, and keep them all in sync, across languages and levels of verbosity.

This of course will only work for static messages - If you compute what you
display, I guess you need to either keep the computation in the displayer, or
pass it in, or something - gets messy.

Keeps the code clear though, as it splits what you display away from the
decision of saying something.

I try to avoid it if I can.

- Hendrik






More information about the Python-list mailing list