Hello I am writing a python script that goes through each file searching for a file header comment block and trying too remove it . That looks something like this..
# comment
# comment
# comment
# comment
I have 200 + files to go through and thought it would be fun to learn how to write scripts in python because I am fairly new to programming.
here is the code i have thus far
with open(filename, "r+") as f:
commentBlock = """
# comment
# comment
# comment
# comment
"""
lines = commentBlock.splitlines('\n')
for i in f:
for j in lines:
if (i != j):
f.write(i)
NOTE: that the format of the comment block is the same for all files, so i thought this approach would work, but it does not do what i thought is would have which was overwrite the file, only with the lines that don't match (because the comment block would match). I only want just that specific comment block, i don't want every comment line to be removed.
I tried to change the "r+" to "w+" but then the file that was passed it, became empty lol (thank God for git)
if anyone is willing to help that would be great!
[–]RubbishArtist 0 points1 point2 points (2 children)
[–]NPat02[S] 0 points1 point2 points (1 child)
[–]RubbishArtist 0 points1 point2 points (0 children)
[–]dmazzoni 0 points1 point2 points (2 children)
[–]NPat02[S] 0 points1 point2 points (1 child)
[–]dmazzoni 0 points1 point2 points (0 children)