Advertisement
niromru

QT Файлы ---> Файлы в файле

Nov 20th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. def tobytes(k, f):
  2.     if f == 'B':
  3.         return int(k)
  4.     if f == 'KB':
  5.         return int(k) * 1024
  6.     if f == 'MB':
  7.         return int(k) * 1024 * 1024
  8.     if f == 'GB':
  9.         return int(k) * 1024 * 1024 * 1024
  10.     if f == 'TB':
  11.         return int(k) * 1024 * 1024 * 1024 * 1024
  12.  
  13.  
  14. def st(x):
  15.     return x[0]
  16.  
  17.  
  18. def tomax(x):
  19.     frs = ['B', 'KB', 'MB', 'GB', 'TB']
  20.     k = 0
  21.     t = x
  22.     while t >= 1024:
  23.         t = t / 1024
  24.         k += 1
  25.     if frs[k] == 'TB':
  26.         t = t * 1024
  27.         k -= 1
  28.     return str(round(t)) + ' ' + frs[k]
  29.  
  30.  
  31. f = open('input.txt', 'r', encoding='utf-8')
  32. s = []
  33. ty = []
  34. sz = []
  35. for i in f:
  36.     s.append(i.strip('\n').split(' '))
  37. f.close()
  38. for i in range(len(s)):
  39.     fr = s[i][0].split('.')[1]
  40.     if fr not in ty:
  41.         sz.append(0)
  42.         ty.append(fr)
  43. ty.sort()
  44. for i in range(len(s)):
  45.     fr = s[i][0].split('.')[1]
  46.     sz[ty.index(fr)] = sz[ty.index(fr)] + tobytes(s[i][1], s[i][2])
  47. s.sort(key=st)
  48. f = open('output.txt', 'w', encoding='utf-8')
  49. for i in range(len(ty)):
  50.     for ii in range(len(s)):
  51.         if s[ii][0].split('.')[1] == ty[i]:
  52.             f.write(s[ii][0] + '\n')
  53.     f.write('----------\n')
  54.     f.write('Summary: ' + tomax(sz[i]) + '\n\n')
  55. f.close()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement