[Tutor] IRC Client Trouble -- too many new lines

Liam Clarke-Hutchinson Liam.Clarke-Hutchinson at business.govt.nz
Tue Sep 20 00:16:17 CEST 2005

Hi Joseph, 

I'm unable to cc to the Python list from this address, so I'll try my
forwarding address.


You know that 'print' adds a newline?
You could either use - 

import sys

or, to simplify things -
I would recommend either - 

space = ' '
for item in msg:

joinedMsg = space.join(msg)


nullString = ''
joinedMsg = nullString.join(msg)
noNewlinesMsg = joinedMsg.replace('\n', nullString)

Let me know how it goes. 


Liam Clarke-Hutchinson
From: Joseph Quigley [mailto:cpu.crazy at gmail.com] 
Sent: Tuesday, 20 September 2005 2:19 a.m.
To: Liam Clarke-Hutchinson; tutor at python.org
Subject: Re: [Tutor] IRC Client Trouble -- too many new lines


Liam Clarke-Hutchinson wrote: 
Hi Joseph, 

while (1):
  	buffer = Data.IRC.recv(1024)
	msg = string.split(buffer)

Just a warning, the string module will be removed/deprecated come Py3K.
Better to use - 
nick_name = msg[0][:msg[0].find("!")]
filetxt.write(nick_name.lstrip(':') + ' -> ' + message.lstrip(':') + '\n')
Ok. Thanks for the heads up.

As to your printing problem, I'm not sure if you're referring to - 
print msg[print_msg]

Oh, sorry. I'm refering to the print msg[print_msg]

And I'm not sure if you want it to print without an additional newline, or
with a newline. 
Well every word is on it's own new line (I get a huge message from the IRC
server) and I'd like a word wrap or something to fix that. 
#Incidentally, it's a bit simpler to maintain this kinda loop
#instead of a while loop.

for item in msg:
    item.rstrip() #Will strip whitespace (\t\r\n etc.) by default
    print item
Ah. Thanks

If you're wanting to print without the newline that print adds, why not do a
join like this one? message = ' '.join(msg[3:])

print ' '.join(msg) ?

Thanks again. This is proving very usefull.

What output you're expecting
I'm expecting a large amount of text without new lines for each word, and
possible word wrapping.

What output you're getting


PS Your code is interesting, I've never dealt with the IRC protocol
before,so it's good to see a demonstration of it.
I edited the code from a Python Cookbook recipe.

 I may toddle off and check
out that RFC.
Yes. Some people on a forum that I hang oput with suggested a chat room. A
freind of mine suggested IRC and python. He's doing the server and I'm doing
the client. I'm testing the client on freenode.. only thing I could think of
at the time.

A new monthly electronic newsletter covering all aspects of MED's work is now available.  Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism.  See http://news.business.govt.nz for more details.

http://www.govt.nz - connecting you to New Zealand central & local government services

Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer.

More information about the Tutor mailing list