Remove single white space from end of lines for .TXT file

Vimzy

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?

selllikesybok

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

While loop through file names and remove white space

분류에서Dev

remove lines from an output file from diff

분류에서Dev

Give command to remove repeated lines but repeated lines have some variation in a .txt file

분류에서Dev

How do I replace a set of single characters and white space with the same characters but no white space

분류에서Dev

Remove extra header lines from file, except for the first line

분류에서Dev

Remove first N lines from an active log file

분류에서Dev

Vim S&R to remove number from end of InstallShield file

분류에서Dev

Need to remove white space between two tags with Regex

분류에서Dev

How to remove Page Header White Space in SSRS report

분류에서Dev

how to remove unwanted vertical white space in visual studio 2013

분류에서Dev

how can I remove white space in a string and replace it with (;) in batch

분류에서Dev

git revert on single lines in single file of commit

분류에서Dev

Curl url txt file, but grep each url separately from single file

분류에서Dev

Space remove from a sentence but not working

분류에서Dev

Batch File: delete lines in a bunch of txt files

분류에서Dev

How to include white space when searching for a string in text file

분류에서Dev

replace varying number of spaces in file with single space

분류에서Dev

What is the size of a single sign in .txt file?

분류에서Dev

Remove lines from file up to a pattern, unless the pattern doesn't exist

분류에서Dev

how do i remove the space at at the end of the column header?

분류에서Dev

batch file create txt file with multiple lines in specific folder

분류에서Dev

visual mode in vi to remove char at the end of multiple lines

분류에서Dev

White Space in UIWebView

분류에서Dev

hover and white space

분류에서Dev

hover and white space

분류에서Dev

white space below footer

분류에서Dev

Xamarin Forms Remove space from Entry

분류에서Dev

Downloading links from a txt file

분류에서Dev

Remove line from file

Related 관련 기사

  1. 1

    While loop through file names and remove white space

  2. 2

    remove lines from an output file from diff

  3. 3

    Give command to remove repeated lines but repeated lines have some variation in a .txt file

  4. 4

    How do I replace a set of single characters and white space with the same characters but no white space

  5. 5

    Remove extra header lines from file, except for the first line

  6. 6

    Remove first N lines from an active log file

  7. 7

    Vim S&R to remove number from end of InstallShield file

  8. 8

    Need to remove white space between two tags with Regex

  9. 9

    How to remove Page Header White Space in SSRS report

  10. 10

    how to remove unwanted vertical white space in visual studio 2013

  11. 11

    how can I remove white space in a string and replace it with (;) in batch

  12. 12

    git revert on single lines in single file of commit

  13. 13

    Curl url txt file, but grep each url separately from single file

  14. 14

    Space remove from a sentence but not working

  15. 15

    Batch File: delete lines in a bunch of txt files

  16. 16

    How to include white space when searching for a string in text file

  17. 17

    replace varying number of spaces in file with single space

  18. 18

    What is the size of a single sign in .txt file?

  19. 19

    Remove lines from file up to a pattern, unless the pattern doesn't exist

  20. 20

    how do i remove the space at at the end of the column header?

  21. 21

    batch file create txt file with multiple lines in specific folder

  22. 22

    visual mode in vi to remove char at the end of multiple lines

  23. 23

    White Space in UIWebView

  24. 24

    hover and white space

  25. 25

    hover and white space

  26. 26

    white space below footer

  27. 27

    Xamarin Forms Remove space from Entry

  28. 28

    Downloading links from a txt file

  29. 29

    Remove line from file

뜨겁다태그

보관