How to parse over a Python expr?

Stefan Franke franke at
Fri Aug 30 22:22:13 CEST 2002

I have a string with a a sequence of substrings, some of which are Python
expressions,  some are not. 

Now I'd like to have a function that attempts to parse this string starting from any 
index n and returning the index of the first character that doesn't belong to the
(longest possible) Python expression starting from n.

1. Can I achieve this with functionality of standard modules (parser..)?

2. I guess any $(expr)-like string interpolation mechanism needs the same 
thing. As does - in a similar fashion, restricted to string literals - any CSV (comma
separated value) parser. 

If there's a way to utilize the Python parser, can the parsed expression be 
limited to some sub-expression, given its start token (similar to 


More information about the Python-list mailing list