diff --git a/dronekit/__init__.py b/dronekit/__init__.py index 7d98364f4..97113e020 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. @@ -87,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): @@ -2822,7 +2827,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)