-
Notifications
You must be signed in to change notification settings - Fork 0
/
abc.py
59 lines (37 loc) · 1.1 KB
/
abc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import re
def replace(match, replacement, text, flags = 0):
return re.sub(match, replacement, text, flags)
def MultipleReplace(text, list, singlepass = False):
if singlepass:
return re.sub(
'|'.join(re.escape(key) for key in list.keys()),
lambda k: list[k.group(0)],
text
)
else:
for key, val in list.items():
text = replace(key, val, text, re.M)
return text
text = 'bananas and apples taste greattttttttttttt'
list = {
'bananas': 'goo',
'tttt': 'yss'
}
def split(delimiter, text, count):
return text.split(delimiter, count)
return re.split(delimiter, text, count)
splitAtSpaceRE = ' (?! )'
def sr(f):
with open(f) as file:
return file.read()
def sw(f, content):
with open(f, 'w') as file:
file.write(content)
def FixPython(f, parser):
text = sr(f)
result = parser(text)
write(f, result)
def FixPythonParser(s):
replacements =objobj
s = replace('.*dn\n', '', s)
s = MultipleReplace(s, replacements, singlepass=True)