Hardware Reference
In-Depth Information
This tells Python that when the 366 response has been received, it should print out the now-
complete list of names to the standard output before blanking the names list again. This last
line— names = [] —is important: without it, each time the loop runs it will add users'
names to the list even though they already exist from an earlier run.
Finally, finish the program by entering the following lines:
time.sleep(irc['namesinterval'])
s.send('NAMES %(channel)s\r\n' % irc)
This tells Python to wait the namesinterval number of seconds before sending another
request for user names and beginning the loop again. Be careful to set namesinterval to a
reasonable value—if the IRC server receives too many requests in too short a space of time,
it may forcibly disconnect you for flooding. .
Save the program as ircuserlist.py , and run it either by using IDLE's Run Module
option in the Run menu or from the terminal by typing python ircuserlist.py . When
the program first runs, it may take a while to connect to the server; once connected, how-
ever, the list of names (see Figure 12-7) should refresh quickly. To quit the program, press
CRTL + C.
Figure 12-7:
Using Python to
list users in an
IRC channel
Search WWH ::




Custom Search