From c44fe4e43322d42059d6758c0e79895ff138d38c Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 2 Oct 2016 20:00:02 +0200 Subject: [PATCH 1/2] Python 3: define basestring, use sbytes.decode() Enables vehicle_state.py to get a few steps closer to liftoff in Python 3 --- dronekit/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dronekit/__init__.py b/dronekit/__init__.py index 7d98364f4..be85beecf 100644 --- a/dronekit/__init__.py +++ b/dronekit/__init__.py @@ -49,7 +49,11 @@ import collections from pymavlink.dialects.v10 import ardupilotmega - +try: + basestring # Python 2 +except NameError: # Python 3 + basestring = (str, bytes) + class APIException(Exception): """ Base class for DroneKit related exceptions. @@ -2822,7 +2826,7 @@ def connect(ip, @vehicle.on_message('STATUSTEXT') def listener(self, name, m): - status_printer(re.sub(r'(^|\n)', '>>> ', m.text.rstrip())) + status_printer(re.sub(r'(^|\n)', '>>> ', m.text.decode('utf-8').rstrip())) if _initialize: vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout) From 8280e351c192cf071378f27dc88f2e250f0527fc Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 3 Oct 2016 09:54:47 +0200 Subject: [PATCH 2/2] Attitude.__str__() --- dronekit/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dronekit/__init__.py b/dronekit/__init__.py index be85beecf..97113e020 100644 --- a/dronekit/__init__.py +++ b/dronekit/__init__.py @@ -91,7 +91,8 @@ def __init__(self, pitch, yaw, roll): self.roll = roll def __str__(self): - return "Attitude:pitch=%s,yaw=%s,roll=%s" % (self.pitch, self.yaw, self.roll) + fmt = '{}:pitch={pitch},yaw={yaw},roll={roll}' + return fmt.format(self.__class__.__name__, **vars(self)) class LocationGlobal(object):