I have a small question. I noticed that, for some reason, when I use the +
symbol when joining two variables, Python automatically uses a newline.
for i in range(o):
a = Before.readline()
b = After.readline()
if a == b:
lines.append(" \n")
else:
plus = a + b
lines.append(a + b)
Final.writelines(lines)
This would result in a list with values as such (Notice the 'B\nC\n'
)
[' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n',
' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n',
'B\nC\n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n', ' \n']
Assuming that I have initialized the files Before
, After
, and Final
correctly, what should I do to remove these newlines and just add a space? I would prefer to do this without using many libraries.
EDIT : I do know about the .strip()
method. It is indeed very helpful, to remove the new lines. However, I seem to have phrased my question a little wrong. I was also wondering about how to add the new lines, as a + ' ' + b
doesn't really seem to work. How would I do this?
DOUBLE EDIT : I'm stupid. I put the wrong variable in the appending area. Nevermind, and thanks anyways!