diff --git a/examples/Python/hwclient.py b/examples/Python/hwclient.py index eb9b58c9..080c57c0 100644 --- a/examples/Python/hwclient.py +++ b/examples/Python/hwclient.py @@ -15,9 +15,9 @@ # Do 10 requests, waiting each time for a response for request in range(10): - print("Sending request %s ..." % request) - socket.send(b"Hello") + print(f"Sending request {request} ...") + socket.send_string("Hello") # Get the reply. message = socket.recv() - print("Received reply %s [ %s ]" % (request, message)) + print(f"Received reply {request} [ {message} ]") diff --git a/examples/Python/hwserver.py b/examples/Python/hwserver.py index f822bb7a..1f9b3609 100644 --- a/examples/Python/hwserver.py +++ b/examples/Python/hwserver.py @@ -14,10 +14,10 @@ while True: # Wait for next request from client message = socket.recv() - print("Received request: %s" % message) + print(f"Received request: {message}") # Do some 'work' time.sleep(1) # Send reply back to client - socket.send(b"World") + socket.send_string("World") diff --git a/examples/Python/tasksink.py b/examples/Python/tasksink.py index 01bb857e..ddbc9008 100644 --- a/examples/Python/tasksink.py +++ b/examples/Python/tasksink.py @@ -32,4 +32,4 @@ # Calculate and report duration of batch tend = time.time() -print("Total elapsed time: %d msec" % ((tend-tstart)*1000)) +print(f"Total elapsed time: {(tend-tstart)*1000} msec") diff --git a/examples/Python/taskvent.py b/examples/Python/taskvent.py index b8db7c2c..448324fa 100644 --- a/examples/Python/taskvent.py +++ b/examples/Python/taskvent.py @@ -8,11 +8,6 @@ import random import time -try: - raw_input -except NameError: - # Python 3 - raw_input = input context = zmq.Context() @@ -25,7 +20,7 @@ sink.connect("tcp://localhost:5558") print("Press Enter when the workers are ready: ") -_ = raw_input() +_ = input() print("Sending tasks to workers...") # The first message is "0" and signals start of batch @@ -42,9 +37,9 @@ workload = random.randint(1, 100) total_msec += workload - sender.send_string(u'%i' % workload) + sender.send_string(f"{workload}") -print("Total expected cost: %s msec" % total_msec) +print(f"Total expected cost: {total_msec} msec") # Give 0MQ time to deliver time.sleep(1) diff --git a/examples/Python/version.py b/examples/Python/version.py index e529ac6f..3567b5aa 100644 --- a/examples/Python/version.py +++ b/examples/Python/version.py @@ -4,5 +4,5 @@ import zmq -print("Current libzmq version is %s" % zmq.zmq_version()) -print("Current pyzmq version is %s" % zmq.__version__) +print(f"Current libzmq version is {zmq.zmq_version()}") +print(f"Current pyzmq version is {zmq.__version__}") diff --git a/examples/Python/wuclient.py b/examples/Python/wuclient.py index 76d81103..7e3c14f8 100644 --- a/examples/Python/wuclient.py +++ b/examples/Python/wuclient.py @@ -17,10 +17,6 @@ # Subscribe to zipcode, default is NYC, 10001 zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001" - -# Python 2 - ascii bytes to unicode str -if isinstance(zip_filter, bytes): - zip_filter = zip_filter.decode('ascii') socket.setsockopt_string(zmq.SUBSCRIBE, zip_filter) # Process 5 updates @@ -30,6 +26,5 @@ zipcode, temperature, relhumidity = string.split() total_temp += int(temperature) -print("Average temperature for zipcode '%s' was %dF" % ( - zip_filter, total_temp / (update_nbr+1)) -) +print((f"Average temperature for zipcode " + f"'{zip_filter}' was {total_temp / (update_nbr+1)} F")) diff --git a/examples/Python/wuserver.py b/examples/Python/wuserver.py index 437f64f6..eaf65c29 100644 --- a/examples/Python/wuserver.py +++ b/examples/Python/wuserver.py @@ -17,4 +17,4 @@ temperature = randrange(-80, 135) relhumidity = randrange(10, 60) - socket.send_string("%i %i %i" % (zipcode, temperature, relhumidity)) + socket.send_string(f"{zipcode} {temperature} {relhumidity}")