Removing all spaces in text file with Python 3.x

前端 未结 3 461
日久生厌
日久生厌 2021-01-14 12:33

So I have this crazy long text file made by my crawler and it for some reason added some spaces inbetween the links, like this:

https://example.com/asdf.html         


        
3条回答
  •  遥遥无期
    2021-01-14 13:11

    You can open file and read line by line and remove white space -

    Python 3.x:

    with open('filename') as f:
        for line in f:
            print(line.strip())
    

    Python 2.x:

    with open('filename') as f:
        for line in f:
            print line.strip()
    

    It will remove space from each line and print it.

    Hope it helps!

提交回复
热议问题