It's working with %s
instead or %r
:
formatter = "%s %s %s %s"
print formatter %(
"I had this thing.\n",
"That you could type up right.\n ",
"But it didn't sing.\n",
"So I said goodnight."
)
%r
uses the repr
method, without formating the special characters :
print(repr('\ntext'))
>>> '\ntext'
print(str('\ntext'))
>>>
text
If you need to keep the raw strings for some lines, you should change the formater to this pattern, and use r"rawstrings with special characters"+'\n'
to add a newline when you need it.
formatter = "{}{}{}{}"
print(formatter.format(
r"C:\n"+'\n',
"That you could type up right.\n",
"But it didn't sing.",
"So I said goodnight."
))
# >>>C:\n
# That you could type up right.
# But it didn't sing.So I said goodnight.
print(formatter.format(
1,2,3,4)
)
# >>> 1234