Jan-03-2021, 11:54 AM
(Jan-03-2021, 03:20 AM)AntaresSky Wrote: So why did that other bit of code not work properly and put the )on the next line?There was
\n
(new line) that should not be there for this task.When use
f.readlines()
it add a \n
automatically.So what i did was to remove all new
\n
(line 16),then do the task.Then last add
\n
with '\n'.join(out_lines)
as writelines()
does not add newline characters on its own.A tips use
repr()
to see all👀 So you add it where you want to take a look.
with open(in_file, 'r+') as f: out_lines = [] for line in f.readlines(): print(repr(line))
with open(in_file, 'r+') as f: out_lines = [] for line in f: line = line.strip() print(repr(line))