I'm trying to use Python to open a .txt file and remove a single white space if it exists from the end of each line, BUT all the new lines and formatting has to remain. I need to check each individual line in the .txt file and if there are any lines with a single space at the end, I need to remove just that single space for those lines, that's it. Everything else must remain intact. Is this possible?
Why not something like:
for line in input_file:
if line.endswith(" \n"):
line = line.replace(' \n', '\n')
Followed by whatever steps you take to collect the reviewed/modified inputs for later outputting.
There may be a cleverer way to do it, but this should work.
Editted to reflect a more readable fix.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다