Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import os |
| 2 | import re |
| 3 | |
| 4 | def write_file(path, data): |
| 5 | wdata = data.rstrip() + "\n" |
| 6 | with open(path, "w") as f: |
| 7 | f.write(wdata) |
| 8 | |
| 9 | def append_file(path, data): |
| 10 | wdata = data.rstrip() + "\n" |
| 11 | with open(path, "a") as f: |
| 12 | f.write(wdata) |
| 13 | |
| 14 | def read_file(path): |
| 15 | data = None |
| 16 | with open(path) as f: |
| 17 | data = f.read() |
| 18 | return data |
| 19 | |
| 20 | def remove_from_file(path, data): |
| 21 | lines = read_file(path).splitlines() |
| 22 | rmdata = data.strip().splitlines() |
| 23 | for l in rmdata: |
| 24 | for c in range(0, lines.count(l)): |
| 25 | i = lines.index(l) |
| 26 | del(lines[i]) |
| 27 | write_file(path, "\n".join(lines)) |