Remove very last character in file

前端 未结 7 1825
说谎
说谎 2020-11-29 08:00

After looking all over the Internet, I\'ve come to this.

Let\'s say I have already made a text file that reads: Hello World

Well, I want to remo

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 08:23

    here is a dirty way (erase & recreate)... i don't advice to use this, but, it's possible to do like this ..

    x = open("file").read()
    os.remove("file")
    open("file").write(x[:-1])
    

提交回复
热议问题