python - 编辑文本文件
我正在使用 python,我想从文本文件末尾删除一些字符。 该文件很大,我不想阅读全部内容并复制有趣的部分。 我最好的猜测是我需要更改文件大小......
任何人都可以帮助我吗 谢谢
I am using python and i want to delete some characters from the end of a text file.
The file is big a and i dont want to read all of it and duplicate the interesting part.
My best guess is that i need to change the file size....
can anyone help me please
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你需要打开文件,查找到末尾,删除字符并保存。
寻求 ( http://docs.python.org/library/stdtypes.html# file.seek )接受负值(例如
f.seek(-3, os.SEEK_END)
将位置设置为倒数第三个),这样您就可以轻松地转到末尾你的文件。http://docs.python.org/library/stdtypes.html#file-对象 - 此链接可能是一个很好的起点。
I guess that you need to open the file, seek to the end, delete characters and save it.
seek ( http://docs.python.org/library/stdtypes.html#file.seek ) accepts negative values (e.g.
f.seek(-3, os.SEEK_END)
sets the position to the third to last), so that you can easily go to the end of your file.http://docs.python.org/library/stdtypes.html#file-objects - this link may be a good starting point.