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

Bischoop Bischoop at vimart.net
Fri Nov 6 08:13:54 EST 2020


On 2020-11-06, Chris Angelico <rosuav at gmail.com> wrote:
> On Fri, Nov 6, 2020 at 11:51 PM Bischoop <Bischoop at vimart.net> wrote:
>>
>> On 2020-11-06, Chris Angelico <rosuav at gmail.com> 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.

Yes, I know about irc libraries but I do it for educational purposes,
when wrtiting it myself I do learn all the time new things.


More information about the Python-list mailing list