【发布时间】:2020-03-24 03:39:29
【问题描述】:
我有 .txt 文件,其中包含以下几个条目
.I 3192
.T
The Lincoln Keyboard - a Typewriter Keyboard Designed
for Computers Input Flexibility
.W
A new typewriter keyboard, for direct and punched paper tape computer input
will replace the usual commercial keyboard with 88 characters chosen for the
convenience of programmers.
.B
CACM July, 1958
.A
Vanderburgh, A.
.N
CA580702 ES March 17, 1982 10:10 AM
.X
1083 5 3192
3192 5 3192
3192 5 3192
该文件一个接一个地包含多个条目。 .I、.T、.W、.B、.A、.N、.X都是条目中的字段。每个新条目都以.I 开头,并一直持续到另一个条目开始。有些条目没有一个或多个字段,换句话说完全跳过了一个或多个字段。
我正在尝试将整个文本文件转换为 csv 文件,其中每一行以下列方式代表一个条目
content of .I、content of .T、content of .W、content of .B、content of .A、content of .N、content of .X
如果任何条目没有该字段,则 csv 文件中该字段的位置应为空值。
【问题讨论】:
-
“我正在尝试”听起来您已经尝试过。你能分享你的方法并强调缺少什么吗?
标签: python-3.x csv text text-processing