Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # reads text file and returns a list of strings
- file = open("data.txt", "r")
- lines = file.readlines()
- file.close()
- data = []
- for line in lines:
- tempRecord = {}
- line = line.strip()
- line = line.split("|")
- tempRecord["name"] = line[2].strip().split("=")[1]
- tempRecord["age"] = line[1]
- data.append(tempRecord)
- saveFile = open("extracted_data.txt", "w")
- for record in data:
- saveFile.write(f'Name :: {record["name"]}\n')
- print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement