Let's look at an example from network programming. We'll be using a TCP socket. The socket.send() method takes a string of input bytes and outputs them to the receiving socket at the other end. There are plenty of libraries that accept sockets and access this function to send data on the stream. Let's create such an object; it will be an interactive shell that waits for a connection from a client and then prompts the user for a string response:
import socketdef respond(client): response = input("Enter a value: ") client.send(bytes(response, "utf8")) client.close()server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)server.bind(("localhost", 2401))server.listen(1)try: while True: client, addr = server.accept() respond(client) ...