Jan-03-2021, 04:05 PM
(This post was last modified: Jan-03-2021, 04:06 PM by AntaresSky.)
Interesting!
So the line in the original script L.Lstrip is different then your script Line.strip?
I take it the Line.Lstrip is telling it to removed the whole line?
But I'm still not totally clear on what the Line.strip does. Can you dumb it down a bit for me?
ORIGINAL SCRIPT:
So the line in the original script L.Lstrip is different then your script Line.strip?
I take it the Line.Lstrip is telling it to removed the whole line?
But I'm still not totally clear on what the Line.strip does. Can you dumb it down a bit for me?
ORIGINAL SCRIPT:
with open(in_file, 'r+') as f: out_lines = [] for line in f.readlines(): if not line.lstrip().startswith(';'): out_lines.append(line) if(len(out_lines) > 0): f.seek(0) f.truncate() f.writelines(out_lines)YOUR NEW AND IMPROVED SCRIPT:
with open(in_file, 'r+') as f: out_lines = [] for line in f: line = line.strip() if line.startswith(';'): out_lines.append(f'({line})') else: out_lines.append(line) if len(out_lines) > 0: f.seek(0) f.truncate() f.write('\n'.join(out_lines)) print(f'comment fix complete for {in_file}')Glen