Python将文本文件解析为csv

时间:2019-07-19 04:21:22

标签: python-3.x csv text

我有一个格式为

的文本文件
rule {
  source: 1
  target: 1
  target_code: 1
}
rule {
  source: 2
  target: 9
  target_code: 3
}

我在下面编写了一个代码来读取文本文件,但无法转换为csv行,例如

source, target, target code
1,1,1
2,9,3

需要指导

# Open a file: file
file = open('routing_rules.txt',mode='r')

# read all lines at once
txt = file.read()
print(txt)



# close the file
file.close()

0 个答案:

没有答案
相关问题