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
#11
(Jan-03-2021, 04:05 PM)AntaresSky Wrote: I take it the Line.Lstrip is telling it to removed the whole line?
str.lstrip() will remove whitespace on the left end of the string, i.e. leading whitespace at the start of the string
str.rstrip() will remove whitespaces on the right end of the string, i.e. trailing whitespace at the end.
str.strip() will remove whitespace on bith ends.

Your best friend is the documentation. If in doubt - check the docs.

so the original line.lstrip() will remove any white space at the start of the line, so that if present the first non-whitespace char will be ; in comments. But it will not remove the new-line char \n at the end.

Also, note that python is case sensitive Line.Lstrip() is not same as line.lstrip() and will cause error.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#12
(Jan-03-2021, 04:05 PM)AntaresSky Wrote: 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?
lstrip() Return a copy of the string with leading whitespace removed.
Can test this interactively in Python.
>>> s = 'hello\n'
>>> s.lstrip()
'hello\n'

>>> s = ' hello\n'
>>> s.lstrip()
'hello\n'

>>> s = '\nhello\n'
>>> s.lstrip()
'hello\n'

>>> s = 'hello\n'
>>> s.strip()
'hello'

>>> help(s.lstrip)
Help on built-in function lstrip:

lstrip(chars=None, /) method of builtins.str instance
    Return a copy of the string with leading whitespace removed.
    
    If chars is given and not None, remove characters in chars instead.


>>> help(s.strip)
Help on built-in function strip:

strip(chars=None, /) method of builtins.str instance
    Return a copy of the string with leading and trailing whitespace removed.
    
    If chars is given and not None, remove characters in chars instead.
Reply
#13
(Jan-03-2021, 06:16 PM)buran Wrote: Your best friend is the documentation. If in doubt - check the docs.
My head is spinning LOL Cry
This document you speak of. where might's I find it?
I think I need to do some reading and learning!!! Smile


Glen
Reply
#14
(Jan-04-2021, 12:06 AM)AntaresSky Wrote: This document you speak of. where might's I find it?
I guess you've seen the links in my previous post.

Official Python documentation - you have Library reference, language reference, tutorial and so on...

As @snippsat show you can also get help in interactive shell
ndc85430 likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Edit Open and Active Excel sheet in Python JoeDainton123 1 735 Jul-29-2020, 12:52 AM
Last Post: Larz60+
  python doc edit and run online? luckrill 0 548 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 1,589 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 886 May-28-2020, 05:27 PM
Last Post: micseydel
  How do I edit saved Python 3 script? Mocap 1 925 Jul-17-2019, 08:41 AM
Last Post: perfringo
  Package python script which has different libraries as a single executable or script tej7gandhi 1 1,253 May-11-2019, 08:12 PM
Last Post: keames
  Need someone to help me edit this script edlentz 1 832 Apr-04-2019, 09:13 PM
Last Post: Larz60+
  Python code for gcode reader and representation ralmeida 1 3,358 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 1,615 May-23-2018, 04:50 PM
Last Post: snippsat
  How to call one python script and use its output in another python script lravikumarvsp 3 27,359 May-16-2018, 02:08 AM
Last Post: lravikumarvsp

Forum Jump:

User Panel Messages

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