PyCmdMessenger icon indicating copy to clipboard operation
PyCmdMessenger copied to clipboard

Python 2.x compatibility

Open sphh opened this issue 8 years ago • 1 comments

Hi Mike,

Some time ago, I had the same problem as @zlite. My solution does keep the same functionality in Python 3.x, but is compatible with 2.x;

There is only one change in PyCmdMessenger.py and the diff is:

@@ -116,7 +116,7 @@
                               "?":self._recv_bool,
                               "g":self._recv_guess}
 
-    def send(self,cmd,*args,arg_formats=None):
+    def send(self,cmd,*args,**kwargs):
         """
         Send a command (which may or may not have associated arguments) to an
         arduino using the CmdMessage protocol.  The command and any parameters
@@ -127,6 +127,10 @@
         arg_formats supercedes formats specified on initialization.
         """
 
+        arg_formats = kwargs.pop('arg_formats', None)
+        if kwargs:
+            raise TypeError("'send()' got unexpected keyword arguments: {}".format(', '.join(kwargs.keys())))
+
         # Turn the command into an integer.
         try:
             command_as_int = self._cmd_name_to_int[cmd]

Maybe the setup.py must also be changed.

I don't know if you want to incorporate it into you code. I can understand it if you don't want to keep backward compatibility. Maybe you just want to add a comment what has to be changed for Python 2.x?

Best wishes, Stephan

sphh avatar Feb 11 '17 17:02 sphh

Good idea to use **kwargs. I'm going to incorporate the change and take away the python 3 requirement. Thanks for all of your input on the library.

harmsm avatar Feb 27 '17 04:02 harmsm