how to determine an 'open' string?

holger krekel pyth at devel.trillke.net
Thu May 16 13:56:20 EDT 2002


Skip Montanaro wrote:
> 
>     holger> with my replacement rlcompleter module i'd like to
>     holger> have a *correct* check if a string is 'open'.
> 
> How about just trying to eval() the string?  Assuming it begins with a
> quotation mark or apostrophe it should be safe to call eval().  Either it's
> a complete string in which case eval() is safe, or it's an open string and
> you get a SyntaxError.  You obviously don't eval stuff that doesn't start
> with other characters.

i have to do this with arbitrary statements/expressions.
Harvey Thomas found a nice solution fit to the problem.

thanks,

    holger





More information about the Python-list mailing list