acbart

Untitled

Nov 3rd, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. with open("file1.txt") as input_file:
  2.     with open("file2.txt") as output_file:
  3.         for line in input_file:
  4.             if line.startswith(">"):
  5.                 name = line.strip()
  6.                 # do something interesting with the name
  7.                 output_file.write(name+"\n")
  8.             else:
  9.                 data = line.strip().split(";")
  10.                 # do something interesting with the data
  11.                 output_file.write(data+"\n")
  12.                
  13. with open("file2.txt") as input_file:
  14.     with open("file3.txt") as output_file:
  15.         for line in input_file:
  16.             if line.startswith(">"):
  17.                 name = line.strip()
  18.                 # do something interesting with the name
  19.                 output_file.write(name+"\n")
  20.             else:
  21.                 data = line.strip().split(";")
  22.                 # do something interesting with the data
  23.                 output_file.write(data+"\n")
  24.                
  25. ########################################################
  26.    
  27. first_data = []
  28. with open("file1.txt") as input_file:
  29.     for line in input_file:
  30.         if line.startswith(">"):
  31.             name = line.strip()
  32.             # do something interesting with the name
  33.         else:
  34.             data = line.strip().split(";")
  35.             # do something interesting with the data
  36.             row = (name, data) # tuple!
  37.             first_data.append(row)
  38.  
  39. second_data = []
  40. for name, data in first_data:
  41.     new_data = # do something to data to make new_data
  42.     row = (name, new_data)
  43.     second_data.append(row)
  44.            
  45. with open("file3.txt") as output_file:
  46.     for name, data in second_data:
  47.         # do something interesting with the name and data
  48.         output_file.write(name+"\n")
  49.         output_file.write(data+"\n)
Advertisement
Add Comment
Please, Sign In to add comment