Advertisement
MagicWinnie

Untitled

Dec 29th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. from PIL import Image
  2. import re
  3.  
  4. #reading
  5. f = open('in.ppm', 'rb')
  6. lines = eval(f.readlines()[-1])
  7. f.close()
  8.  
  9. #getting head
  10. b = b''
  11. for i in range(0,len(lines)-1):
  12.     b+=lines[i:i+1]
  13.     if lines[i-3:i] == b'255':
  14.         break
  15. b = b.decode()
  16. b = re.sub(' +', ' ', b).strip().rstrip().splitlines()
  17. while ' ' in b:
  18.     b.remove(' ')
  19.  
  20. #getting map
  21. d = lines[i+1:]
  22.  
  23. #getting maxval, width and height
  24. maxval = b[-1]
  25. first = 0
  26. for i in range(len(b)):
  27.     if b[i].split()[0].isdigit() and first == 0:
  28.         width = int(b[i].split()[0])
  29.         first = 1
  30.     elif b[i].split()[0].isdigit() and first != 0:
  31.         height = int(b[i].split()[0])
  32.         break
  33.  
  34. #getting comments
  35. arr_comments = []
  36. for i in range(len(b)):    
  37.     if b[i].find('#') != -1:
  38.         if b[i].find('!') != -1 and (b[i][1]=='!' or b[i][2] == '!'):
  39.             arr_comments.append(b[i].replace('#', '').replace('!', '').split())
  40.  
  41. print(arr_comments)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement