Python
  Home arrow Python arrow Page 3 - Python and IRC
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Python and IRC
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 29
    2005-02-16

    Table of Contents:
  • Python and IRC
  • Hello IRC World
  • Can You Hear Me?
  • I Can Hear You!
  • IRC Mathematics

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    Python and IRC - Can You Hear Me?
    (Page 3 of 5 )

    Now that we know how to connect, our next task is joining a channel and sending a message to its occupants. This is suprisingly easy.

    import socket

    network = 'irc.insert.a.network.here'
    port = 6667
    irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
    irc.connect ( ( network, port ) )
    irc.send ( 'NICK PyIRC\r\n' )
    irc.send ( 'USER PyIRC PyIRC PyIRC :Python IRC\r\n' )
    irc.send ( 'JOIN #pyirc\r\n' )
    irc.send ( 'PRIVMSG #pyirc :Can you hear me?\r\n' )
    irc.send ( 'PART #pyirc\r\n' )
    irc.send ( 'QUIT\r\n' )
    irc.close()

    Note that, again, the code will probably not perform the instructions we gave it, for the same reason as last time. However, the above code would ideally join the channel #pyirc and say "Can you hear me?" Let's break the code down to see how it works. The first few lines should already look familiar, and the last few lines should look familiar as well. We wrote them in the previous section. However, the "JOIN," "PRIVMGS," and "PART" lines are new. They simply join the channel, send a message to the channel and leave the channel, respectively.

    To join multiple channels, just issue the "JOIN" command again. When sending a message, be sure to specify the name of the channel in the "PRIVMSG" command. You can also message another user with the "PRIVMSG" command.

    import socket

    network = 'irc.insert.a.network.here'
    port = 6667
    irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
    irc.connect ( ( network, port ) )
    irc.send ( 'NICK PyIRC\r\n' )
    irc.send ( 'USER PyIRC PyIRC PyIRC :Python IRC\r\n' )
    irc.send ( 'PRIVMSG Jimbo :Can you hear me?\r\n' )
    irc.send ( 'QUIT\r\n' )
    irc.close()

    More Python Articles
    More By Peyton McCullough


       · Hey, all. I thought this would be a unique topic to write about. I haven't seen...
       · very nice article, it's very rare to see someone talking about writing scripts for...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway