Come si fa a indirizzare dati restituiti ad una presa in Python?
Domanda
Diciamo che sono un telnet in IRC per capire come funziona il tutto. Come ti comanda rilascio, le restituisce i dati del server IRC che ti dice quello che sta facendo. Una volta che ho creato uno script di default che, in fondo è come una connessione IRC normale tra server e client si verifica, se mai si discosta da che non mi dirà ciò che è sbagliato. Ho bisogno di essere in grado di generare eccezioni in base a ciò il server restituisce a me. Come faccio a farlo in Python?
Soluzione
Ecco un tutorial che ti guida praticamente attraverso un client IRC utilizzando i socket in Python:
Altri suggerimenti
ritorto è un motore di networking event-driven scritto in Python, e include il supporto per i protocolli IRC
. Per accedere alla funzionalità IRC
, importarlo:
from twisted.words.protocols import irc
Vedere un esempio qui : ircLogBot.py - si collega a un server IRC e registra tutti i messaggi. L'esempio __doc__
:
"""An example IRC log bot - logs a channel's events to a file.
If someone says the bot's name in the channel followed by a ':',
e.g.
<foo> logbot: hello!
the bot will reply:
<logbot> foo: I am a log bot
Run this script with two arguments, the channel name the bot should
connect to, and file to log to, e.g.:
$ python ircLogBot.py test test.log
will log channel #test to the file 'test.log'.
"""