PYTHON IS CRAP

Ben Wolfson rumjuggler at cryptarchy.org
Thu Aug 17 05:35:39 EDT 2000


On Thu, 17 Aug 2000 09:53:31 +0200, "Alex Martelli" <alex at magenta.com>
wrote:

>"Vespe Savikko" <vespe at cs.tut.fi> wrote in message
>news:vphaeeca1i2.fsf at hiirihaukka.cs.tut.fi...
>> Also sprach David Bolen <db3l at fitlinxx.com>:
>>
>>   Yeah, but that's still less convenient than just do something like:
>>
>>   > pyman string.split
>>
>>   (e.g., a direct lookup on precisely the API entry you are interested
>>   in, in just the way it gets used by the application)
>>
>> In most (?) cases doc strings do just that:
>
>They surely should, so here's a first-cut attempt at pyman.py:

[snip neat script, examples]

>This little script no doubt could and should be enhanced,
>made more robust, etc, etc, for example with switches to
>get at richer info than just docstrings, and so on.  But
>I hope it can provide a basis for you to apply whatever
>such enhancements you desire.

One obvious improvement:

C:\Python16>python pyman.py httplib.HTTP.__init__
Sorry, can't import 'httplib.HTTP.__init__': No module named httplib HTTP

Isn't terribly helpful, since there is, after all, a docstring for that
function.  Uglifying do_import() to:

def do_import(name):
    components = string.split(name, '.')
    mod = None
    if len(components) == 1:
        mod = getattr(__builtin__, name, None)
    if not mod:
        while 1:
            try:
                name = components[0]
                mod = __import__(name)
            except ImportError:
                if len(components) == 1:
                    break
                components[1] = components[0] + '.' + compenents[1]
                components = components[1:]
            else:
                break
    if not mod:
        raise ImportError
    for comp in components[1:]:
        mod = getattr(mod, comp)
    return mod

And trapping for (AttributeError,ImportError) instead of
(ValueError,ImportError) in explain() fix it, but there's a better way.

C:\Python16>python pyman.py httplib.HTTP.__init__
Initialize a new instance.

        If specified, `host' is the name of the remote host to which
        to connect.  If specified, `port' specifies the port to which
        to connect.  By default, httplib.HTTP_PORT is used.

-- 
Barnabas T. Rumjuggler's page of dumbth: members.home.net/rumjuggler

During the festive holiday season, make something your subbie-girl will
cherish by using your hot-glue gun to attach gold and silver beads to her
nipple clamps!  It's a good thing.
 -- Darla, the Martha Stewart of BDSM, on ark



More information about the Python-list mailing list