Jan-03-2021, 03:06 AM
Some fix done,try this.
import sys import os if len(sys.argv) != 2: print('Usage: python nocomment.py <file.gcode>') sys.exit(1) in_file = os.path.abspath(sys.argv[1]) if not os.path.isfile(in_file): print(f'{in_file} does not exist!') sys.exit(1) 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 removal complete for {in_file}')