test if an input string starts with a python expression

Torsten Mohr tmohr at s.netic.de
Mon Dec 7 18:39:13 EST 2009


Hi,

i'd like to test if an input string starts with a python expression
and also where that expression ends.  An example:

a_func(3*7, '''abc''') +5 pls some more

The first part until (inclusive) the 5 should be found as an expression
and the length of that string should also be detected.


Background is that i want to embed some python expressions in a text
and i want to evaluate them later.
It is possible that the embedded expressions span several lines.

Alternatively, is it possible to define a start- and an end-marker
that define the embedded expression and find the expression using
a regular expression?
If the expression contains strings, these strings could contain
the end-marker which should not be found inside strings.

Example:

start: <
end:   >

< some_func(r">")>


Can anybody tell me how to do this best?

Can i do this using just modules from the python library?


Thanks for any hints,
Torsten.




More information about the Python-list mailing list