python IRC buffer not clearing
I have a simply buffer system for my IRC bot so it never misses a line due to network lag and such. I am using the following code to start the loop that processes information received from the server:
while 1: #Start the main loop
self.readbuffer += s.recv(1024).decode()
temp=self.readbuffer.split("\n")
self.readbuffer=temp.pop()
The problem is that it seems that the buffer never clears, so any time I want to do something with the d开发者_Python百科ata it loops through everything. So if I tell the bot to do something, it does everything it's done before as well. Through debugging I've confirmed that the buffer is indeed never clearing. So... based on the code above (the only code that ever modifies the buffer) what is my problem? Thanks for reading.
Where do you try to clear the buffer?
self.readbuffer += s.recv(1024).decode()
adds more data to readbuffer.
temp=self.readbuffer.split("\n")
turns readbuffer into a list of one-line strings
self.readbuffer=temp.pop()
makes readbuffer the last line
If readbuffer never gets smaller, it must be because you never receive a newline character. Perhaps IRC uses '\r'
or some other code to indicate a new post?
精彩评论