sxw's recent timeline updates
sxw

sxw

V2EX member #164295, joined on 2016-03-21 19:44:01 +08:00
sxw's recent replies
Jun 2, 2021
Replied to a topic by join Linux 如何修改一个大文件?
@join 抱歉没写清楚,我回复的是 #10
Jun 2, 2021
Replied to a topic by join Linux 如何修改一个大文件?
@join 可以用 "r+" 打开文件,seek 到要修改的地方。https://es2q.com/blog/2019/02/22/modify_file_without_rewrite/
根据 @tabris17 的方法,用 python3 实现是:

```python
import os
f = os.open('test_file', os.O_RDWR|os.O_CREAT)
os.ftruncate(f, os.path.getsize('test_file') - 2)
os.close(f)
```

耗时几毫秒
@tabris17 非常感谢,弄好了
@rrfeng 请问 seek 怎么操作呢?用什么方式打开文件?我尝试用 'w+' 和 'w' 打开文件 seek 再关闭,都会清空文件。
我提了工单,客服说:“功能上没有区别,信用程度上企业账户更高”
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3777 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 21ms · UTC 04:34 · PVG 12:34 · LAX 21:34 · JFK 00:34
♥ Do have faith in what you're doing.