Quotation Ugliness

Ben Finney ben+python at benfinney.id.au
Wed Nov 26 02:54:45 CET 2014

Tim Daneliuk <tundra at tundraware.com> writes:

> Here's the problem: Determine is the string S appears *outside* or
> *inside* any such quotation.

This is a problem for parsing text. There is no general, simple

If someone tries to convince you they have one, be highly suspicious: it
will either be not general, or not simple, or neither simple nor general.

> I know lots of ugly/complicated/heavyweight ways to solve this, but
> I'm wondering if any of you geniuses have a pythonic/elegant/short
> algo that solves this.

I would recommend one of the following, in descending order of

* Try very hard to change the requirements so that the input must be in
  a mature well-known format for which there are *existing*, maintained,
  reliable parsers. Use those instead of rolling your own.

* If that fails, then: Try very hard to drastically simplify the
  specified input format so that every possible input is either
  obviously invalid, or obviously has exactly one meaning.

* If that fails, then: Bite the bullet and acknowledge you will be
  entering the complexities of parsing text. Use a mature library for
  writing your parser; don't attempt to write a parsing library
  yourself. *This is the worst option*; changing the requirements for
  input will be much less pain than this.

 \       “Fear him, which after he hath killed hath power to cast into |
  `\   hell; yea, I say unto you, Fear him.” –Jesus, as quoted in Luke |
_o__)                                                             12:5 |
Ben Finney

More information about the Python-list mailing list