Python Forum
Help moding python script to edit Gcode
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help moding python script to edit Gcode
#10
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:
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
Reply


Messages In This Thread
RE: Help moding python script to edit Gcode - by AntaresSky - Jan-03-2021, 04:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,734 Jun-29-2023, 11:57 AM
Last Post: gologica
  Edit Open and Active Excel sheet in Python JoeDainton123 1 2,194 Jul-29-2020, 12:52 AM
Last Post: Larz60+
  python doc edit and run online? luckrill 0 1,666 Jul-09-2020, 01:28 PM
Last Post: luckrill
  How to kill a bash script running as root from a python script? jc_lafleur 4 6,167 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,419 May-28-2020, 05:27 PM
Last Post: micseydel
  How do I edit saved Python 3 script? Mocap 1 2,144 Jul-17-2019, 08:41 AM
Last Post: perfringo
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,717 May-11-2019, 08:12 PM
Last Post: keames
  Need someone to help me edit this script edlentz 1 2,001 Apr-04-2019, 09:13 PM
Last Post: Larz60+
  Python code for gcode reader and representation ralmeida 1 6,355 Jul-31-2018, 09:20 AM
Last Post: DeaD_EyE
  How to run python script which has dependent python script in another folder? PrateekG 1 3,242 May-23-2018, 04:50 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020