[Newbie] Is the text delimiter changeable?

Peter Hansen peter at engcorp.com
Sun Jun 30 12:12:53 EDT 2002


Ben Fairbank wrote:
> 
> I have to process large amounts of text and the text includes numerous
> apostrophes and quotation marks.  It would be very handy if I could
> temporarily assign a substitute for Python's use of the caracters "
> and ' to delimit text strings.  If I could use, for example, the @
> character or the # character, neither of which appears in the text I
> have to work with, and if I could disable the " and ' delimiters, then
> my task would be greatly simplified.  I realize I can backslash escape
> these characters in some circumstances, but I do not think that will
> work when a user's input is a word such as "can't" or "don't."
> Anyway, short of doing something truly drastic, such as recompiling
> the system (which I have no intention of doing), is there a workaround
> that will permit this?

Do you know about Python's triple-quoted strings?

>>> a = """This isn't much of a "string" now, is it?"""
>>> b = '''This can't have "triple-quotes" inside, of course, but that's okay.'''

-Peter



More information about the Python-list mailing list