4

I have a large ASCII logo that I want to store in a docstring. This logo features multiple instances of three consecutive double quotation marks. The size and complexity is such that escaping individual characters isn't a realistic option. Given that at no point is an instance of three consecutive double quotation marks in isolation on a line, how can this logo be stored in a docstring?

Here is a minimal example:

logo = """
hello"""world
"""

The resulting error is as follows:

    hello"""world
                ^
SyntaxError: invalid syntax
d3pd
  • 7,935
  • 24
  • 76
  • 127

3 Answers3

4

Just use the single-quotes.

logo = '''
hello"""world
'''

If you don't want to violate PEP8, you can be a bit hackish

logo = """
hello'''world
""".replace("'", '"')
Eli Korvigo
  • 10,265
  • 6
  • 47
  • 73
0

You can "violate" PEP8 and use ''':

logo = '''
       hello"""world
       '''
DeepSpace
  • 78,697
  • 11
  • 109
  • 154
0

I seems backslashes work as well

>>> """ \"\"\" """
' """ '
>>> 
John
  • 13,197
  • 7
  • 51
  • 101