[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Incoming datas difficult to read "\r\n" and "\n"

On Fri, Nov 6, 2020 at 11:51 PM Bischoop <Bischoop at> wrote:
> On 2020-11-06, Chris Angelico <rosuav at> wrote:
> > You're currently dumping out the raw bytes. Not very interesting, and
> > that's why it's not easy to read. I would recommend (a) decoding the
> > bytes to text, and (b) splitting it on "\r\n", thus getting it
> > line-by-line.
> >
> > What you may want to consider, though, is using an actual IRC library.
> > It'll handle all kinds of details for you :)
> >
> right
> I've changed the line to:
> print(data.decode('utf8'))
> and prints it now nice but not sure how to apply yet:
> print (string.splitlines( ))
> and PING PONG matter.

Cool. You're going to have to iterate over the lines and process each
one individually. IRC is a line-based protocol and every line has its
own meaning. But, again, this is where an IRC library would help
enormously; it'll do all of that parsing (including taking care of
edge cases that you might not have thought of), and let you just
handle the parts that are interesting, like responding to specific
messages from people.