Home
Sign Up
Sign In
V2EX
›
问与答
Python 在每个文件里插入一段文本在首行,要怎么实现呢?
zeroday
·
Aug 29, 2015
· 6074 views
This topic created in 4086 days ago, the information mentioned may be changed or developed.
形如这个形式的
--- layout: post title: xxxxx (原先文本的第一行) category: code tags: code description: ---
Code
文本
XXXXX
layout
4 replies
•
2015-08-30 11:39:44 +08:00
shierji
Aug 29, 2015 via Android
1
按行读 然后重定位文件指针 你看下文档吧
bearzk
Aug 29, 2015
1
2
with open ('filename', 'r') as original:
data = original.read ()
with open ('filename', 'w') as modified:
modified.write ("new first line\n" + data )
bearzk
Aug 29, 2015
3
不好意思上面的代码写进去没有缩进 你自己缩进试试看
zeroday
OP
Aug 30, 2015
4
@
bearzk
谢谢,我明白你的思路了。
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Privacy
·
Solana
·
2621 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 29ms ·
UTC 14:08
·
PVG 22:08
·
LAX 06:08
·
JFK 09:08
♥ Do have faith in what you're doing.
❯