Skip to content

PluginPython23

OllisGit edited this page Apr 8, 2020 · 5 revisions

If you want to move your plugin from Python2 to Pyhton 3, be aware of the following stuff:

init.py

__plugin_name__ = "Your Plugin"
__plugin_pythoncompat__ = ">=2.7,<4"

YourPlugin.md

compatibility:
  python: ">=2.7,<4"

Python 3 stuff

Workaround for import-handling

import sys
is_py2 = sys.version[0] == '2'
if is_py2:
    import Queue as queue
else:
    import queue as queue

Octolapse.gcode_parser changes

unicode vs str

if (isinstance(cmd, str) == True):
    command_string = cmd
else:
    # needed to handle non utf-8 characters
    command_string = cmd.encode('ascii', 'ignore')

has_key

    #if any(filter(parameters.has_key, additional_parameters.keys())):
    
    self._myParameters = parameters
    if any(filter( self.hasKeyReplacement  , additional_parameters.keys())):
...
    def hasKeyReplacement(self, key1):
        result = key1 in self._myParameters
        return result