Advertisement
Guest User

Untitled

a guest
Oct 12th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. file_path = '../my_image.ppm'
  2. settings = []
  3. data = []
  4.  
  5. with open(file_path) as f:
  6.     for line in f:
  7.         hash_position = line.find('#')
  8.         if hash_position == 0 or not line:
  9.             continue
  10.         elif hash_position > 0:
  11.             line = line[:hash_position]
  12.         splitted_line = line.split()
  13.  
  14.         if len(settings) < 4:
  15.             length_diff = len(splitted_line) + len(settings) - 4
  16.             if length_diff > 0 and settings:
  17.                 data.extend(list(map(int, splitted_line[-length_diff:])))
  18.                 settings.extend(splitted_line[:-1])
  19.             else:
  20.                 settings.extend(splitted_line)
  21.         else:
  22.             data.extend(list(map(int, splitted_line)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement