[Python-ideas] Mutable chars objects

Jason Orendorff jason.orendorff at gmail.com
Sun Mar 11 21:53:17 CET 2007


On 3/11/07, Talin <talin at acm.org> wrote:
> I do a lot of stuff with parsing, and its often convenient to build up
> long strings of text one character at a time.

Could you be more specific about this?  When I write a parser it
always starts with either

  _token_re = re.compile(r'''(?x)
     ...15 lines omitted...
     ''')

or

  import yapps2  # wheeee!

I've never had much luck hand-coding a lexer in straight-up Python.
Not only is it slow, I feel like Python's syntax is working against
me-- no switch statement, no do-while.  (This is not a complaint!
It's all right.  I should be using a parser-generator anyway.)

Josiah mentioned array.array('c').  There's also array.array('u'),
which is an array of Py_UNICODEs.  You can add the string methods in a
subclass for a quick prototype.

-j



More information about the Python-ideas mailing list