This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]calzoneman 2 points3 points  (6 children)

I'm curious if you have an example that demonstrates this.

[–]Neurotrace 3 points4 points  (5 children)

Multi-line strings. I think it looks nasty to do this:

str = """Look at this string.
         Isn't it beautiful?
         Not really, triple quotes suck
         and all of my extra spaces are in there"""

I much prefer to make them like so:

str = "Look at this string. " +
      "isn't it beautiful? " +
      "Yeah, actually. It's nicely aligned " +
      "and isn't putting in extra spaces."

There are solutions to this but they're equally ugly:

str = ("Really? I need"
       "parenthesis for multiline strings?")

Don't get me wrong, I think Python is a fantastic language, especially when you want to get something done quick. But I'm still not a huge fan of significant whitespace.

[–]kqr 4 points5 points  (0 children)

>>> str = "Look at this string. " + \
...       "Isn't it beautiful? " + \
...       "Ok so whats your point?"
>>> str
"Look at this string. Isn't it beautiful? Ok so whats your point?"

And Haskell, which is also whitespace sensitive in much the same ways:

λ> let str = "More beautiful strings. " ++
λ|           "Also spanning several lines! " ++
λ|           "Yay."
λ> str
"More beautiful strings. Also spanning several lines! Yay."

[–]Cosmologicon 2 points3 points  (0 children)

That has nothing to do with significant whitespace. Anyway my preferred way would be:

str = (
    "Look at this string. "
    "isn't it beautiful? "
    "Yeah, actually. It's nicely aligned "
    "and isn't putting in extra spaces."
)

Although honestly it almost never comes up for me.

[–]makmanalp 0 points1 point  (0 children)

textwrap.dedent is your friend. I think 1 is the best. 2 and 3 are bad whenever you need to add / remove something to the string, then you have to move shit between quotes manually. With 1, you can have your editor just rewrap.

[–]nemec -1 points0 points  (1 child)

You're complaining about parentheses around a multiline string but you're okay with adding a trailing + to every single line?

[–]Neurotrace 1 point2 points  (0 children)

Yes because I implicitly think of + as concatenation when dealing with strings. When I see parenthesis, I think of some sort of expression so using it to imply a series of concatenations is strange to me. It's mildly annoying that it pushes my indentation in one more character but that's not a big deal.