how to determine an 'open' string?

holger krekel pyth at devel.trillke.net
Thu May 16 11:16:37 EDT 2002


Sean 'Shaleh' Perry wrote:
> 
> On 16-May-2002 holger krekel wrote:
> > hello, 
> > 
> > with my replacement rlcompleter module i'd like to
> > have a *correct* check if a string is 'open'.
> > examples:
> > 
> >     asd"""askdjalsdk      # open 
> >     aksdjasd              # closed
> >     asjdkk"kajsd''''      # open
> >     "'asdasd"             # closed
> >     """dontcountoneven"   # open
> > 
> > so i need a function which takes these strings as
> > an argument and return 1 for 'open', 0 for a 'closed' string.
> > 
> 
> Seems a really simple solution is count the number of each type of quote in the
> string.  But first you need to find all of the triple quotes.

i thought along those lines, too, but couldn't get it correct easily. 

> for each quote type:
>   count = find all triple quotes
>   if count is even: closed

for
    """''' askldjl'''

this returns 'closed': wrong!

    holger





More information about the Python-list mailing list