wing-ide

Python: TypeError: str, bytes or bytearray expected, not int

假如想象 提交于 2019-12-02 12:09:43
问题 I'm trying to create a simple server to client based chat program and the issue is that when I try to execute c.sendto(data,client) this error appears saying that Client is an int but it's a tuple containing the port number and the address. I'm I supposed to convert the tuple to bytes so I can send the message to the clients? Server Script import socket clients = [] s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("127.0.0.1",7999)) s.listen() print("Waiting for connection") c,

How can I print to console while the program is running in python? [duplicate]

吃可爱长大的小学妹 提交于 2019-11-30 13:10:40
Possible Duplicate: How to flush output of Python print? I have have an algorithm that I'm running that takes a while, so I want to keep track of how far it's through, by printing to the console. So something like: import sys def myMethod(): i = 0 while (i<1000000): i = i+1 output_str = str(i) + "\n" sys.stdout.write(output_str) # same as print sys.stdout.flush() myMethod() How can I have this print while it's running, rather than at the end? Edit, Solution: - Posted amended code. This code works fine when you run it in the linux terminal using python filename.py But when I run it in Wing 101