Changing the default string object used by the interpreter

Peter Otten __peter__ at web.de
Sun Apr 11 02:34:44 EDT 2004


Mike McGavin wrote:

> I'm wondering if anyone can suggest a way, short of directly hacking the
> python interpreter, to change the default str class to a different one.
>   ie. So that every time a str instance is created, it uses *my* class
> instead of the built-in python string.  Is there anything hidden away
> that can be overloaded that might make this possible to do?

You could have a look at Quixote, which changes (literal) strings to
htmltext in their .ptl templates. It's done by manipulation of the AST
(file ptl_compile.py). That is the least intrusive strategy I can think of.

Peter




More information about the Python-list mailing list