-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrimfile.py
More file actions
32 lines (27 loc) · 719 Bytes
/
Copy pathtrimfile.py
File metadata and controls
32 lines (27 loc) · 719 Bytes
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
import random
def read_indexes(filename):
print(f"Reading {filename}")
f = open(filename, "r")
terms = []
for line in f:
if(line != "\n"):
temp = line.replace("'", "").replace("\"", "")
terms.append(temp)
return terms
def write_indexes(filename, list):
print(f"Writing to {filename}")
f = open(filename, "w")
for item in list:
f.write(item)
f.close()
print("Finished writing.")
def trim(filename):
print("Removing whitespace.")
try:
content = read_indexes(filename)
except Exception as e:
print(e)
return
write_indexes(filename, content)
if __name__ == "__main__":
trim(input("filename: "))