mirror of
https://github.com/ThomasToka/MarlinFirmware.git
synced 2024-11-12 07:10:23 +00:00
Specify encoding for gcode file and improve error handling
This commit is contained in:
parent
439bc81406
commit
170532d353
@ -13,9 +13,15 @@ import os
|
||||
# Get the g-code source file name
|
||||
sourceFile = sys.argv[1]
|
||||
|
||||
# Read the ENTIRE g-code file into memory
|
||||
with open(sourceFile, "r") as f:
|
||||
lines = f.readlines()
|
||||
try:
|
||||
# Read the ENTIRE g-code file into memory
|
||||
with open(sourceFile, "r", encoding="utf8") as f:
|
||||
lines = f.readlines()
|
||||
except Exception as e:
|
||||
print("Error opening source file: {0}".format(str(e)))
|
||||
input()
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
new_lines = []
|
||||
remove_next_line = False
|
||||
@ -32,11 +38,10 @@ for line in lines:
|
||||
new_lines.append(line)
|
||||
|
||||
try:
|
||||
with open(sourceFile, "w+") as of:
|
||||
with open(sourceFile, "w+", encoding="utf8") as of:
|
||||
of.write(''.join(new_lines))
|
||||
except:
|
||||
print('Error writing output file')
|
||||
except Exception as e:
|
||||
print("Error writing output file: {0}".format(str(e)))
|
||||
input()
|
||||
finally:
|
||||
of.close()
|
||||
f.close()
|
||||
|
Loading…
Reference in New Issue
Block a user