-1

I have a file in the following format:

G1 X113.901 Y66.179 E225.40813
G1 X114.212 Y66.611 E227.87255
G1 X114.396 Y67.11 E230.33708
G1 X114.452 Y67.78 E233.45031
G1 X114.057 Y71.888 E252.56566

It's from a slicer and I want to use it in a 3D-Printer, but the part with Exxx.xxxxx needs to be removed. Is there a way in python to read the text file and remove just this part?

gre_gor
  • 6,669
  • 9
  • 47
  • 52

1 Answers1

0

You can use regex:

import re

t = '''
G1 X113.901 Y66.179 E225.40813

G1 X114.212 Y66.611 E227.87255

G1 X114.396 Y67.11 E230.33708

G1 X114.452 Y67.78 E233.45031

G1 X114.057 Y71.888 E252.56566
'''

pattern = re.compile(r'E[0-9]+\.[0-9]+')

print(re.sub(pattern, "", t))
matszwecja
  • 6,357
  • 2
  • 10
  • 17