I know this is probably an easy one but I am still new to Python and need a little push in the right direction. I have a text file that I need a certain number of spaces where on character 88 an N is placed going on to the new line. The test file I am using looks like this:
aaaa aaaaa
What my desired output (for testing) would look like this:
aaaa N aaaaa N
With my coding I am getting
aaaa N aaaaa N
I have tried to manually code it (no if statements) but get the output above:
`newf=””
with open(‘testfile.txt’,’r’) as f:
for line in f:
newf+=line.strip()+" Nn"
f.close()
with open(‘testfile.txt’,’w’) as f:
f.write(newf)
f.close()`
I have tried an in-statement but keep getting errors
spacef = "" newf="" with open('testfile.txt','r') as f: for line in f: if newf <= 88: newf+=line.strip()+" " f.close() with open('testfile.txt','w') as f: f.write(newf) f.close()
IndentationError: expected an indented block after ‘if’ statement on line 5
Any help would be appreciated
adding if statement