Advertisement
kingbode

Untitled

Feb 4th, 2023
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. # reads text file and returns a list of strings
  2.  
  3. file = open("data.txt", "r")
  4. lines = file.readlines()
  5. file.close()
  6.  
  7. data = []
  8.  
  9. for line in lines:
  10.     tempRecord = {}
  11.     line = line.strip()
  12.     line = line.split("|")
  13.     tempRecord["name"] = line[2].strip().split("=")[1]
  14.     tempRecord["age"] = line[1]
  15.     data.append(tempRecord)
  16.  
  17.  
  18. saveFile = open("extracted_data.txt", "w")
  19. for record in data:
  20.     saveFile.write(f'Name :: {record["name"]}\n')
  21.  
  22. print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement