multiline strings and proper indentation/alignment

Dave Hansen iddw at hotmail.com
Wed May 10 20:23:14 CEST 2006


On Wed, 10 May 2006 15:50:38 GMT in comp.lang.python, John Salerno
<johnjsal at NOSPAMgmail.com> wrote:

>Dave Hansen wrote:
>
>>>>> print textwrap.dedent(s).strip().replace('\n',' ')
>> this is a multiline triple-quted string with indentation for nicer
>> code formatting
>
>But I have some newlines that are already embedded in the string, and I 
>wouldn't want those replaced.

>>> s = """
	I want the following line-
	concatenated, but leave this
	line break alone.
	"""
>>> print textwrap.dedent(s).strip().replace('-\n',' ')
I want the following line concatenated, but leave this
line break alone.
>>> 

But I'd still recommend using parens and string concatentation.

>>> s2 = (
	"I want the following line "
	"concatentated, but leave this\n"
	"line break alone."
	)
>>> print s2
I want the following line concatentated, but leave this
line break alone.

Regards,
                                        -=Dave

-- 
Change is inevitable, progress is not.



More information about the Python-list mailing list