diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py index 524e4662d5..ed37e93a18 100644 --- a/plugins/GCodeProfileReader/GCodeProfileReader.py +++ b/plugins/GCodeProfileReader/GCodeProfileReader.py @@ -30,14 +30,15 @@ class GCodeProfileReader(ProfileReader): # None \endcode is returned. def read(self, file_name): prefix = ";SETTING_" + str(version) + " " - + prefix_length = len(prefix) + #Loading all settings from the file. They are all at the end, but Python has no reverse seek any more since Python3. TODO: Consider moving settings to the start? serialised = "" #Will be filled with the serialised profile. try: with open(file_name) as f: for line in f: if line.startswith(prefix): - serialised += line[len(prefix):-1] #Remove the prefix and the newline from the line, and add it to the rest. + serialised += line[prefix_length : -1] #Remove the prefix and the newline from the line, and add it to the rest. except IOError as e: Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e)) return None diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index 20a32f7822..a94735c2a2 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -15,7 +15,7 @@ class GCodeWriter(MeshWriter): # written with. If the file format is changed in a way that breaks reverse # compatibility, increment this version number! version = 1 - + def __init__(self): super().__init__() @@ -44,6 +44,7 @@ class GCodeWriter(MeshWriter): # \return A serialised string of the profile. def _serialiseProfile(self, profile): prefix = ";SETTING_" + str(version) + " " #The prefix to put before each line. + prefix_length = len(prefix) serialised = profile.serialise() @@ -60,8 +61,8 @@ class GCodeWriter(MeshWriter): #Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix. result = "" - for pos in range(0, len(serialised), 80 - len(prefix)): #Lines have 80 characters, so the payload of each line is 80 - prefix. - result += prefix + serialised[pos : pos + 80 - len(prefix)] + "\n" + for pos in range(0, len(serialised), 80 - prefix_length): #Lines have 80 characters, so the payload of each line is 80 - prefix. + result += prefix + serialised[pos : pos + 80 - prefix_length] + "\n" serialised = result return serialised \ No newline at end of file