Content-Length: 263322 | pFad | http://github.com/unrealapex/python-programming/commit/6dda33c04817290347c5a17e52696f1d6dd4491a

2B Fixed problem with file reading · unrealapex/python-programming@6dda33c · GitHub
Skip to content

Commit 6dda33c

Browse files
committed
Fixed problem with file reading
1 parent 096eab2 commit 6dda33c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lab-12/occurance-remover.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# TODO: make sure that program does not overwrite file contents
2+
import os
3+
def occurance_remover(file_path, removal_string):
4+
target_file = open(file_path, "r+")
5+
occurances = target_file.read().count(removal_string)
6+
if removal_string in target_file.read():
7+
removal_string = removal_string.replace(removal_string, "")
8+
target_file.close()
9+
print(f"Removed {occurances} of {removal_string} from {os.path.basename(file_path)}")
10+
11+
12+
occurance_remover(r"C:\Users\s158658\src\python-programming\lab-12\test.txt", "foo")

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/unrealapex/python-programming/commit/6dda33c04817290347c5a17e52696f1d6dd4491a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy