improve file2json
This commit is contained in:
Родитель
44055881b1
Коммит
45cb24500f
|
@ -13,8 +13,15 @@ VARNAME - the variable to store it in (the output will be VARNAME = [...])
|
|||
import os, sys
|
||||
|
||||
data = open(sys.argv[1], 'r').read()
|
||||
sdata = map(lambda x: str(ord(x)), data)
|
||||
json = '[' + ','.join(sdata) + ']'
|
||||
sdata = map(lambda x: str(ord(x)) + ',', data)
|
||||
sdata[-1] = sdata[-1].replace(',', '')
|
||||
lined = []
|
||||
while len(sdata) > 0:
|
||||
lined += sdata[:30]
|
||||
sdata = sdata[30:]
|
||||
if len(sdata) > 0:
|
||||
lined += ['\n']
|
||||
json = '[' + ''.join(lined) + ']'
|
||||
|
||||
print 'var ' + sys.argv[2] + '=' + json + ';'
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче