文件输出.txt
First name: Petar
Last Name: Petrovic
Age: 32
Country: USA
This is some description
First name: Nick
Last Name: Cave
Age: 22
Country: Brasil
This is another description
如何使用python脚本获得以下输出:
Petar Petrovic 32 USA
Nick Cave 22 Brasil
到目前为止,我有这个
#!/bin/python
import sys
import os
import re
with open ("output.txt", "r") as myfile:
data=myfile.read()
我读到我可能会使用字典,但不知道如何实现这一点
@Aran Fey肯定有一个更简单的答案,但既然我已经写好了,还有另一个选择:
您可以使用正则表达式:
输出:
相关问题 更多 >
编程相关推荐