-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment_cleaner.py
More file actions
34 lines (24 loc) · 840 Bytes
/
comment_cleaner.py
File metadata and controls
34 lines (24 loc) · 840 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
33
34
def remove_python_comments(input_file, output_file):
"""
Removes single-line comments from a Python file.
"""
try:
with open(input_file, "r", encoding="utf-8") as source_file:
lines = source_file.readlines()
except FileNotFoundError:
print("Input file not found. Please check the file name.")
return
cleaned_lines = []
for line in lines:
stripped = line.lstrip()
if stripped.startswith("#"):
continue
cleaned_lines.append(line)
with open(output_file, "w", encoding="utf-8") as output_file:
output_file.writelines(cleaned_lines)
print("Comment cleaning completed successfully.")
if __name__ == "__main__":
remove_python_comments(
"transaction_manager.py",
"transaction_manager_cleaned.py"
)