Spaces:
Runtime error
Runtime error
Update replace_explitives.py
Browse files- replace_explitives.py +7 -3
replace_explitives.py
CHANGED
@@ -29,12 +29,16 @@ def sub_explitives(textfile, selection):
|
|
29 |
target_word = []
|
30 |
|
31 |
print("selection:", selection, "target_word:", target_word)
|
|
|
32 |
|
33 |
if target_word:
|
34 |
print("target word was found, ", target_word)
|
35 |
print(textfile)
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
|
|
|
40 |
return textfile
|
|
|
29 |
target_word = []
|
30 |
|
31 |
print("selection:", selection, "target_word:", target_word)
|
32 |
+
lines = textfile.split('\n')
|
33 |
|
34 |
if target_word:
|
35 |
print("target word was found, ", target_word)
|
36 |
print(textfile)
|
37 |
+
for i, line in enumerate(lines):
|
38 |
+
for target_word in target_words:
|
39 |
+
pattern = r"\b" + re.escape(target_word) + r"\b"
|
40 |
+
# textfile = re.sub(target_word, replacetext, textfile, flags=re.IGNORECASE)
|
41 |
+
lines[i] = re.sub(pattern, replacetext, lines[i], flags=re.IGNORECASE)
|
42 |
|
43 |
+
textfile = '\n'.join(lines)
|
44 |
return textfile
|