title: parsing gcode file to extract coordinates
body: <p>I have a gcode file that is full of text, more specifically coordinated for a machine. I am trying to read the file, strip away the useless information so that I can then perform an operation on the coordinated before they are sent out to the machine. </p>
  
  <p>so far I have:</p>
  
  <pre><code>file = open('TestCube.gcode','r')
  lines = file.readlines()
  file.close
  
  for line in lines:
      line = line.strip() 
  </code></pre>
  
  <p>Now I have a list of all the lines in the file how should I proceed in getting the relevant X and Y coordinates? </p>
  
  <p>sample fo TestCube.gcode:</p>
  
  <pre><code>;TYPE:SKIN
  G1 F1200 X-9.914 Y-9.843 E3.36222
  G0 F9000 X-9.843 Y-9.914
  G1 F1200 X9.914 Y9.843 E3.65844
  G0 F9000 X9.914 Y9.702
  G1 F1200 X-9.702 Y-9.914 E3.95254
  G0 F9000 X-9.560 Y-9.914
  G1 F1200 X9.914 Y9.560 E4.24451
  G0 F9000 X9.914 Y9.419
  G1 F1200 X-9.419 Y-9.914 E4.53437
  G0 F9000 X-9.277 Y-9.914
  G1 F1200 X9.914 Y9.277 E4.82211
  G0 F9000 X9.914 Y9.136
  G1 F1200 X-9.136 Y-9.914 E5.10772
  G0 F9000 X-8.995 Y-9.914
  G1 F1200 X9.914 Y8.995 E5.39123
  G0 F9000 X9.914 Y8.853
  G1 F1200 X-8.853 Y-9.914 E5.67260
  </code></pre>
  
  <p>EDIT:</p>
  
  <pre><code>import re
  
  file = open('TestCube.gcode','r')
  gcode = file.readlines()
  
  for line in gcode:
      coord = re.findall(r'[XY]-\d.\d\d\d', line)
      if coord:
          print("{} - {}".format(coord[0], coord[1]))
  </code></pre>