python - 编辑文本文件

发布于 2024-09-18 17:38:09 字数 106 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没结果 2024-09-25 17:38:09

我想你需要打开文件,查找到末尾,删除字符并保存。

寻求 ( 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文