how to determine an 'open' string?

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


Terry Reedy wrote:
> 
> "holger krekel" <pyth at devel.trillke.net> wrote in message
> news:mailman.1021560087.23138.python-list at python.org...
> > 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.
> >
> > Any working ideas?
> 
> What means 'open'?  A few examples do not a definition make. Write a
> complete definition (one that applies to all strings) that *you*
> regard as correct and think you are willing to live with.  Then
> translate to code (probably the easier part).

sorry. i was to implicit in denoting that i refer
to the known python rules for the definition.
probably i thought that the reference of 'rlcompleter'
gave enough context.

the question is more exactly:

Given a string S, does S end in an unmatched or matched
quotation (quotation marks beeing ',",""",'''). 
The matching rules are those of our beloved python.

And no, the code was not exactly obvious. There are many ways how
you can do it wrongly :-)

Harvey Thomas has already solved this nicely. 

    holger





More information about the Python-list mailing list