style: use .format() in various places instead of "%" formatting
diff --git a/serial/tools/hexlify_codec.py b/serial/tools/hexlify_codec.py
index 635f7d3..1371da2 100644
--- a/serial/tools/hexlify_codec.py
+++ b/serial/tools/hexlify_codec.py
@@ -91,7 +91,7 @@
state = 0
else:
if self.errors == 'strict':
- raise UnicodeError('non-hex digit found: %r' % c)
+ raise UnicodeError('non-hex digit found: {!r}'.format(c))
self.state = state
return serial.to_bytes(encoded)
diff --git a/serial/tools/list_ports.py b/serial/tools/list_ports.py
index 8041c70..2271dd1 100644
--- a/serial/tools/list_ports.py
+++ b/serial/tools/list_ports.py
@@ -29,7 +29,7 @@
from serial.tools.list_ports_posix import comports
#~ elif os.name == 'java':
else:
- raise ImportError("Sorry: no implementation for your platform ('%s') available" % (os.name,))
+ raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name))
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -79,7 +79,7 @@
# get iteraror w/ or w/o filter
if args.regexp:
if not args.quiet:
- sys.stderr.write("Filtered list with regexp: %r\n" % (args.regexp,))
+ sys.stderr.write("Filtered list with regexp: {!r}\n".format(args.regexp))
iterator = sorted(grep(args.regexp))
else:
iterator = sorted(comports())
diff --git a/serial/tools/list_ports_linux.py b/serial/tools/list_ports_linux.py
index f957efe..567df6d 100644
--- a/serial/tools/list_ports_linux.py
+++ b/serial/tools/list_ports_linux.py
@@ -20,8 +20,8 @@
super(SysFS, self).__init__(device)
self.name = os.path.basename(device)
self.usb_device_path = None
- if os.path.exists('/sys/class/tty/%s/device' % (self.name,)):
- self.device_path = os.path.realpath('/sys/class/tty/%s/device' % (self.name,))
+ if os.path.exists('/sys/class/tty/{}/device'.format(self.name)):
+ self.device_path = os.path.realpath('/sys/class/tty/{}/device'.format(self.name))
self.subsystem = os.path.basename(os.path.realpath(os.path.join(self.device_path, 'subsystem')))
else:
self.device_path = None
@@ -81,4 +81,4 @@
# test
if __name__ == '__main__':
for port, desc, hwid in sorted(comports()):
- print("%s: %s [%s]" % (port, desc, hwid))
+ print("{}: {} [{}]".format(port, desc, hwid))
diff --git a/serial/tools/list_ports_osx.py b/serial/tools/list_ports_osx.py
index 55ef7f4..1d57b96 100644
--- a/serial/tools/list_ports_osx.py
+++ b/serial/tools/list_ports_osx.py
@@ -256,4 +256,4 @@
# test
if __name__ == '__main__':
for port, desc, hwid in sorted(comports()):
- print("%s: %s [%s]" % (port, desc, hwid))
+ print("{}: {} [{}]".format(port, desc, hwid))
diff --git a/serial/tools/list_ports_posix.py b/serial/tools/list_ports_posix.py
index 1901e60..6ea4db9 100644
--- a/serial/tools/list_ports_posix.py
+++ b/serial/tools/list_ports_posix.py
@@ -86,16 +86,16 @@
! I you know how the serial ports are named send this information to
! the author of this module:
-sys.platform = %r
-os.name = %r
-pySerial version = %s
+sys.platform = {!r}
+os.name = {!r}
+pySerial version = {}
also add the naming scheme of the serial ports and with a bit luck you can get
this module running...
-""" % (sys.platform, os.name, serial.VERSION))
- raise ImportError("Sorry: no implementation for your platform ('%s') available" % (os.name,))
+""".format(sys.platform, os.name, serial.VERSION))
+ raise ImportError("Sorry: no implementation for your platform ('{}') available".format(os.name))
# test
if __name__ == '__main__':
for port, desc, hwid in sorted(comports()):
- print("%s: %s [%s]" % (port, desc, hwid))
+ print("{}: {} [{}]".format(port, desc, hwid))
diff --git a/serial/tools/list_ports_windows.py b/serial/tools/list_ports_windows.py
index 89f3db7..a2922f8 100644
--- a/serial/tools/list_ports_windows.py
+++ b/serial/tools/list_ports_windows.py
@@ -66,12 +66,12 @@
]
def __str__(self):
- return "{%08x-%04x-%04x-%s-%s}" % (
+ return "{{{:08x}-{:04x}-{:04x}-{}-{}}}".format(
self.Data1,
self.Data2,
self.Data3,
- ''.join(["%02x" % d for d in self.Data4[:2]]),
- ''.join(["%02x" % d for d in self.Data4[2:]]),
+ ''.join(["{:02x}".format(d) for d in self.Data4[:2]]),
+ ''.join(["{:02x}".format(d) for d in self.Data4[2:]]),
)
@@ -84,7 +84,7 @@
]
def __str__(self):
- return "ClassGuid:%s DevInst:%s" % (self.ClassGuid, self.DevInst)
+ return "ClassGuid:{} DevInst:{}".format(self.ClassGuid, self.DevInst)
PSP_DEVINFO_DATA = ctypes.POINTER(SP_DEVINFO_DATA)
@@ -246,7 +246,7 @@
location = []
for g in m:
if g.group(1):
- location.append('%d' % (int(g.group(1)) + 1))
+ location.append('{:d}'.format(int(g.group(1)) + 1))
else:
if len(location) > 1:
location.append('.')
@@ -297,4 +297,4 @@
# test
if __name__ == '__main__':
for port, desc, hwid in sorted(comports()):
- print("%s: %s [%s]" % (port, desc, hwid))
+ print("{}: {} [{}]".format(port, desc, hwid))
diff --git a/serial/tools/miniterm.py b/serial/tools/miniterm.py
index 420bf12..145996f 100644
--- a/serial/tools/miniterm.py
+++ b/serial/tools/miniterm.py
@@ -32,7 +32,7 @@
"""generate a readable description for a key"""
ascii_code = ord(character)
if ascii_code < 32:
- return 'Ctrl+%c' % (ord('@') + ascii_code)
+ return 'Ctrl+{:c}'.format(ord('@') + ascii_code)
else:
return repr(character)
@@ -322,7 +322,6 @@
sys.stderr.write('\n--- Available ports:\n')
ports = []
for n, (port, desc, hwid) in enumerate(sorted(comports()), 1):
- #~ sys.stderr.write('--- %-20s %s [%s]\n' % (port, desc, hwid))
sys.stderr.write('--- {:2}: {:20} {}\n'.format(n, port, desc))
ports.append(port)
while True: