determining the number of output arguments

Fernando Perez fperez528 at yahoo.com
Mon Nov 15 17:03:36 EST 2004


Alex Martelli wrote:

> Fernando Perez <fperez528 at yahoo.com> wrote:
> 
>> suspect that by playing very nasty tricks with sys._getframe(), the dis
>> and the inspect modules, you probably _could_ get to this information, at
>> least if the caller is NOT a C extension module.  But I'm not even 100%
>> sure this works, and it would most certainly the kind of black magic I'm
>> sure you are not asking about.  But given the level of expertise here, I
>> better cover my ass ;-)
> 
> Yep, that's the cookbook recipe Jp was mentioning -- Sami Hangaslammi's
> recipe 284742, to be precise.  Yep, it _is_ going into the printed 2nd
> edition (which I'm supposed to be working on right now -- deadline
> closing in, help, help!-).

Well, I feel pretty good now: I didn't see Jp's mention of this, and just
guessed it should be doable with those three tools.  I just looked it up, and
it seems it's exactly what I had in mind :)  Cute hack, but I tend to agree
with Scott Daniels' comment that this kind of cleverness tends to promote
rather unreadable code.  Maybe I just haven't seen a good use for it, but I
think I'd rather stick with more explicit mechanisms than this.

Anyway, is it true that this will only work for non-extension code?  If you are
being called from a C extension, dis & friends are toast, no?

Cheers,

f




More information about the Python-list mailing list