I have to write an application that searches for some constant strings in a file/database (they haven't told me which it is yet, and it really doesn't matter for this post).
Anyway, these strings tend to be long (over 200 characters at times) and even with a fairly large monitor, this starts scrolling off the screen (well, I also have multiple windows open at once). Anyway, I would like to breakup the string for readability reasons, so I thought about triple-quoting the sucker with a bunch of newlines, but triple quoting keeps the newlines.
I suppose I could do
myStr = """some
long
string""".replace('\n', '')
But then I fear that they might one day require me to have newlines in myStr
, so that's a bust. Even otherwise, the .replace(...)
will have to be done every time the program runs, which is just not efficient. For the same reason, the following will also not work:
myStr = "some" + \
"long" + \
"string"
So I wonder what alternative ways there might be, to break up a really long string, keeping readability and code-efficiency in mind
Python 2.7 and 3.3 compatibility is a plus
I often do this in my code (which complies with PEP8):
The parenthesis just evaluates the expression(s) into a single string.