File size: 516 Bytes
6fe9fd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
d = open('app/ui.py', 'rb').read()

# [` " ' ] = 5b 60 22 27 5d  ->  [` " ] = 5b 60 22 5d
old_cc = bytes([0x5b, 0x60, 0x22, 0x27, 0x5d])  # [`"']
new_cc = bytes([0x5b, 0x60, 0x22, 0x5d])          # [`"]

count = d.count(old_cc)
print(f'occurrences of [`"\']: {count}')
d2 = d.replace(old_cc, new_cc)
open('app/ui.py', 'wb').write(d2)
print('written, size:', len(d2))

# Verify
d3 = open('app/ui.py', 'rb').read()
i = d3.find(b'createMatch = text.match')
end = d3.find(b'\r\n', i)
print('new line:', repr(d3[i:end]))