REFACTOR replace % op with format were it is easy

This commit is contained in:
Patrick Kanzler 2016-01-08 03:43:33 +01:00
parent f25521f22f
commit 41c6afd3b8
4 changed files with 11 additions and 11 deletions

View File

@ -90,7 +90,7 @@ def echo(args): # pylint: disable=unused-argument
epson.barcode(data, bctype, 48, 2, '', '')
epson.set(align='left')
else:
epson.text('%s\n' % line)
epson.text('{0}\n'.format(line))
except KeyboardInterrupt:
epson.cut()
@ -143,7 +143,7 @@ def _test_barcodes():
):
# TODO: Fix the library to restore old alignment somehow
epson.set(align='center')
epson.text('\n%s\n' % name)
epson.text('\n{0}\n'.format(name))
epson.barcode(data, name, 64, 2, '', '')

View File

@ -348,12 +348,12 @@ class Escpos(object):
if 1 <= height <= 255:
self._raw(BARCODE_HEIGHT + chr(height))
else:
raise BarcodeSizeError("height = %s" % height)
raise BarcodeSizeError("height = {height}".format(height=height))
# Width
if 2 <= width <= 6:
self._raw(BARCODE_WIDTH + chr(width))
else:
raise BarcodeSizeError("width = %s" % width)
raise BarcodeSizeError("width = {width}".format(width=width))
# Font
if font.upper() == "B":
self._raw(BARCODE_FONT_B)

View File

@ -46,7 +46,7 @@ class BarcodeTypeError(Error):
self.resultcode = 10
def __str__(self):
return "No Barcode type is defined (%s)" % self.msg
return "No Barcode type is defined ({msg})".format(msg=self.msg)
class BarcodeSizeError(Error):
@ -62,7 +62,7 @@ class BarcodeSizeError(Error):
self.resultcode = 20
def __str__(self):
return "Barcode size is out of range (%s)" % self.msg
return "Barcode size is out of range ({msg})".format(msg=self.msg)
class BarcodeCodeError(Error):

View File

@ -56,13 +56,13 @@ class Usb(Escpos):
self.device.detach_kernel_driver(0)
except usb.core.USBError as e:
if check_driver is not None:
print("Could not detatch kernel driver: %s" % str(e))
print("Could not detatch kernel driver: {0}".format(str(e)))
try:
self.device.set_configuration()
self.device.reset()
except usb.core.USBError as e:
print("Could not set configuration: %s" % str(e))
print("Could not set configuration: {0}".format(str(e)))
def _raw(self, msg):
""" Print any command sent in raw format
@ -120,7 +120,7 @@ class Serial(Escpos):
if self.device is not None:
print("Serial printer enabled")
else:
print("Unable to open serial printer on: %s" % self.devfile)
print("Unable to open serial printer on: {0}".format(str(self.devfile)))
def _raw(self, msg):
""" Print any command sent in raw format
@ -159,7 +159,7 @@ class Network(Escpos):
self.device.connect((self.host, self.port))
if self.device is None:
print("Could not open socket for %s" % self.host)
print("Could not open socket for {0}".format(self.host))
def _raw(self, msg):
""" Print any command sent in raw format
@ -195,7 +195,7 @@ class File(Escpos):
self.device = open(self.devfile, "wb")
if self.device is None:
print("Could not open the specified file %s" % self.devfile)
print("Could not open the specified file {0}".format(self.devfile))
def flush(self):
""" Flush printing content """