python关键字以什么开头_python替换;如果行以关键字开头,则替换为

我有一个文本文件,包含数千个条目,例如:@INBOOK{Abu-Lughod1991,

chapter = {Writing against culture},

pages = {137-162},

title = {Recapturing anthropology},

publisher = {School of American Research Press},

year = {1991},

editor = {Richard Fox},

author = {Abu-Lughod, Lila},

address = {Santa Fe /NM},

abstract = {Im Zusammenhang mit der Debatte um die writing culture fomuliert AL

eine feministische Kritik und zeigt, wie von dort doch Anregungen

für die Reflektion der Schreibweise und Repräsentation gekommen sind.*},

crossref = {Rabinow1986},

keywords = {Frauen; Feminismus; Erzählung als EG; Repräsentation; Roman; Schreibtechnik;

James Clifford; writing culture; Dialog;},

owner = {xko},

systematik1 = {Anth\theor\Ethnographie},

systematik2 = {Anth\theor\Text & Ges},

timestamp = {1995-12-02}

}

我将把关键字字段中的分号替换为逗号。但仅在“关键字”字段中-其他字段应保持不变:

^{pr2}$

我不是一个程序员,也许下面的代码片段是一个很好的起点,如果有人能完成我将非常感激。在outfile = open("literatur_comma.txt", "w")

for line in open("literatur_semicolon.txt", "r"):

if line # starts with "keywords" replace all semicolon with comma

outfile.write(line) # write in new file

outfile.close()

非常感谢!在

编辑:

谢谢你的答案和代码,太好了!

我在思想上犯了一个错误,如果我使用代码包装器(带outfile),那么它会创建一个包含关键字的新文件。

如何使用同一个文件,并且只将分号替换为关键字行中的逗号?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值