We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 096eab2 commit 6dda33cCopy full SHA for 6dda33c
lab-12/occurance-remover.py
@@ -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