I am trying to save to a txt a multi-line string without the newline and any multiple spaces:
with open('test.txt','w') as f:
f.write( r"""<rect
x="0"
y="0"
width="%s"
height="%s"
stroke="red"
stroke-width="1"
fill-opacity="0" />""" %(3,4)+"\n" )
When I open the file cat 'text.txt'
the file is on multiple lines. How can I have the code written in a single line without multiple white spaces?
<rect x="0" y="0" width="3" height="4" stroke="red" stroke-width="1" fill-opacity="0" />
Without using for instance "".join()
or other methods which will affect the readability of the code?
Using .replace('\n', '')
will not delete the multiple white space.