Quantcast
Channel: Extracting a parenthesized Python expression from a string - Stack Overflow
Browsing index pages (5 articles)
↧

Extracting a parenthesized Python expression from a string

I've been wondering about how hard it would be to write some Python code to search a string for the index of a substring of the form ${expr}, for example, where expr is meant to be a Python expression...

View Article


Answer by Edward Z. Yang for Extracting a parenthesized Python expression...

I think your best bet is to match for all curly braced entries, and then check against Python itself whether or not it's valid Python, for which compiler would be helpful.

View Article


Answer by Jay for Extracting a parenthesized Python expression from a string

I think what you're asking about is being able to insert Python code into text files to be evaluated. There are several modules that already exist to provide this kind of functionality. You can check...

View Article

Answer by Constantin for Extracting a parenthesized Python expression from a...

If you want to handle arbitrary expressions like {'{spam': 42}["spam}"], you can't get away without full-blown parser.

View Article

Answer by zaphod for Extracting a parenthesized Python expression from a string

After posting this, reading the replies so far (thanks everyone!), and thinking about the problem for a while, here is the best approach I've been able to come up with:Find the first ${.Find the next }...

View Article

Browsing index pages (5 articles)


Latest Images