[Twisted-Python] Documentation Question

Being new to twisted I may be lacking a clue, but finding the proper arguments to twisted.application.internet.UDPServer() was a major pain in the butt. Only by looking at the code could I find all the valid arguments and that took a lot of tracing because the valid arguments are determined by listenudp() it seems. Is their an easier way or is it always frustrating to determine the acceptable arguments to an init function? Thanks, Steve

On Mon, 10 Nov 2003, Steven Bauer <bauer@mit.edu> wrote:
Did you try using help(internet.UDPServer) from the interactive interpreter? Here's what I got: class UDPServer(_AbstractServer) | Serve UDP clients | | Call listenUDP when the service starts, with the | arguments given to the constructor. When the service stops, | stop listening. I checked in a fix to make it say "reactor.listenUDP" -- I guess it was just a blindspot of me, I knew what listenUDP means :) Anyway, this should not have required any "looking at the code". Hopefully with my fix you'll be able to know you should do help(reactor.listenUDP) to get the information you're after:
help(reactor.listenUDP) Help on method listenUDP in module twisted.internet.default:
listenUDP(self, port, protocol, interface='', maxPacketSize=8192) method of twis ted.internet.default.SelectReactor instance Connects a given L{DatagramProtocol} to the given numeric UDP port. I realize that the indirection is a pain, but it'd be somewhat annoying (not impossible, though) to lose it, and I would prefer not to do it unless it's a real deal breaker for someone. In general, I highly recommend using help() from the interactive interpreter to read the docstrings of stuff, and see how to call it. If this strategy does not give you information for a specific method/class, you should file a documentation bug in http://twistedmatrix.com/bugs -- while ideally everything should have a docstring, the developers have so much time, so prioritizing by stuff people need is a necessity.

In general, I highly recommend using help() from the interactive interpreter to read the docstrings of stuff, and see how to call it.
You can always start using Stani's Python Editor SPE ( http://spe.pycs.net/ ) which automagically shows you the docstring and required parameterlist. ;-)

On 14 Nov 2003 06:24:12 -0000, Moshe Zadka <twisted@zadka.site.co.il> wrote:
In general, I highly recommend using help() from the interactive interpreter to read the docstrings of stuff, and see how to call it.
And with IPython it's even simpler, e.g. "help reactor.listenUDP". IPython does the parens for you, allowing for new heights of laziness. :) If the docstrings aren't enough and you want to see the source after all, "psource reactor.listenUDP" shows you the source for just that single function, in pretty colors, even. And you can't beat the tab completion: "reactor.listen<TAB>" shows you lots of interesting things. Sure, it's slow to load, but IPython takes the interactive Python experience to a whole new level, especially in situations like this where you're exploring new (to you) code. Oh yeah, try the @pdb option, which automatically launches the debugger *at the point of failure* when an uncaught exception occurs. Alas, since the reactor catches all exceptions, this won't help much with Twisted apps. _jpl_ (a satisfied customer)

John Landahl wrote:
I too love ipython :) Especially since the deep reload command works fairly well. Has macros too. You can access the lines that you type in as a list. Which makes getting a copy of code you type in there easier. Oh and you can use !ls for shell commands. More features at the website: http://ipython.scipy.org/ Have fun! http://www.holepit.com/

Moshe Zadka [twisted@zadka.site.co.il] wrote:
(I am replying off list so that I don't have to wait for moderator approval.) Thanks for your helpful reply. I had looked at the web documentation and interactive help however I evidently have a blind spot for the very first sentence. :) I repeatedly skimmed down to the function I am interested in and saw: __init__(self, *args, **kwargs) Not being able to find out what these arguments were *right there* in the documentation I immediately just checked the code. This didn't take long at all of course just annoying. I then ran into the same issue with one of the other server classes and figured I must be missing something. Turns out I was evidently literally missing something in the documentation. :) So far though Twisted is a great system. Thanks for your work and reply. -Steve

On Mon, 10 Nov 2003, Steven Bauer <bauer@mit.edu> wrote:
Did you try using help(internet.UDPServer) from the interactive interpreter? Here's what I got: class UDPServer(_AbstractServer) | Serve UDP clients | | Call listenUDP when the service starts, with the | arguments given to the constructor. When the service stops, | stop listening. I checked in a fix to make it say "reactor.listenUDP" -- I guess it was just a blindspot of me, I knew what listenUDP means :) Anyway, this should not have required any "looking at the code". Hopefully with my fix you'll be able to know you should do help(reactor.listenUDP) to get the information you're after:
help(reactor.listenUDP) Help on method listenUDP in module twisted.internet.default:
listenUDP(self, port, protocol, interface='', maxPacketSize=8192) method of twis ted.internet.default.SelectReactor instance Connects a given L{DatagramProtocol} to the given numeric UDP port. I realize that the indirection is a pain, but it'd be somewhat annoying (not impossible, though) to lose it, and I would prefer not to do it unless it's a real deal breaker for someone. In general, I highly recommend using help() from the interactive interpreter to read the docstrings of stuff, and see how to call it. If this strategy does not give you information for a specific method/class, you should file a documentation bug in http://twistedmatrix.com/bugs -- while ideally everything should have a docstring, the developers have so much time, so prioritizing by stuff people need is a necessity.

In general, I highly recommend using help() from the interactive interpreter to read the docstrings of stuff, and see how to call it.
You can always start using Stani's Python Editor SPE ( http://spe.pycs.net/ ) which automagically shows you the docstring and required parameterlist. ;-)

On 14 Nov 2003 06:24:12 -0000, Moshe Zadka <twisted@zadka.site.co.il> wrote:
In general, I highly recommend using help() from the interactive interpreter to read the docstrings of stuff, and see how to call it.
And with IPython it's even simpler, e.g. "help reactor.listenUDP". IPython does the parens for you, allowing for new heights of laziness. :) If the docstrings aren't enough and you want to see the source after all, "psource reactor.listenUDP" shows you the source for just that single function, in pretty colors, even. And you can't beat the tab completion: "reactor.listen<TAB>" shows you lots of interesting things. Sure, it's slow to load, but IPython takes the interactive Python experience to a whole new level, especially in situations like this where you're exploring new (to you) code. Oh yeah, try the @pdb option, which automatically launches the debugger *at the point of failure* when an uncaught exception occurs. Alas, since the reactor catches all exceptions, this won't help much with Twisted apps. _jpl_ (a satisfied customer)

John Landahl wrote:
I too love ipython :) Especially since the deep reload command works fairly well. Has macros too. You can access the lines that you type in as a list. Which makes getting a copy of code you type in there easier. Oh and you can use !ls for shell commands. More features at the website: http://ipython.scipy.org/ Have fun! http://www.holepit.com/

Moshe Zadka [twisted@zadka.site.co.il] wrote:
(I am replying off list so that I don't have to wait for moderator approval.) Thanks for your helpful reply. I had looked at the web documentation and interactive help however I evidently have a blind spot for the very first sentence. :) I repeatedly skimmed down to the function I am interested in and saw: __init__(self, *args, **kwargs) Not being able to find out what these arguments were *right there* in the documentation I immediately just checked the code. This didn't take long at all of course just annoying. I then ran into the same issue with one of the other server classes and figured I must be missing something. Turns out I was evidently literally missing something in the documentation. :) So far though Twisted is a great system. Thanks for your work and reply. -Steve
participants (5)
-
John Landahl
-
Moshe Zadka
-
Rene Dudfield
-
Rudy Schockaert
-
Steven Bauer