Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file_path = '../my_image.ppm'
- settings = []
- data = []
- with open(file_path) as f:
- for line in f:
- hash_position = line.find('#')
- if hash_position == 0 or not line:
- continue
- elif hash_position > 0:
- line = line[:hash_position]
- splitted_line = line.split()
- if len(settings) < 4:
- length_diff = len(splitted_line) + len(settings) - 4
- if length_diff > 0 and settings:
- data.extend(list(map(int, splitted_line[-length_diff:])))
- settings.extend(splitted_line[:-1])
- else:
- settings.extend(splitted_line)
- else:
- data.extend(list(map(int, splitted_line)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement