【发布时间】:2022-12-02 13:55:37
【问题描述】:
Anybody can advise what could be wrong with my code?
I am trying to make a method that removes the single line comments from the content.
Also, the method should return the single line comments that start with \'#\'.
import os
def deleteComments(file):
try:
my_file = open(file, \'r\')
data = my_file.read()
clean = \"\"
comment= 0
if i[0] == \"#\":
comment += 1
else:
pass
with open(\"clean-\", \"w\") as f:
f.write(clean)
f.close()
my_file.close()
except:
print(\"An error occurred with accessing the files\")
return file
def deleteComment(file):
try:
my_file = open(file, \'r\')
data = my_file.read()
clean = \"\"
comment= 0
if i[0] == \"#\":
comment += 1
else:
pass
with open(\"clean-\", \"w\") as f:
f.write(clean)
f.close()
my_file.close()
except:
print(\"An error occurred with accessing the files\")
return file
标签: python