osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is this mailbox manipulation working by luck, or can't I understand my own code?


Chris Green <cl at isbd.net> wrote:
> Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> > Chris Green <cl at isbd.net> writes:
> > >msg.get
> > 
> >   You can get some information about ?get?:
> > 
> > print( "msg.get.__doc__ =", msg.get.__doc__ )
> > print( "msg.get.__func__ =", msg.get.__func__ )
> > print( "msg.get.__self__ =", msg.get.__self__ )
> > print( "msg.get.__str__() =", msg.get.__str__() )
> > print( "msg.get.__repr__() =", msg.get.__repr__() )
> > print( "msg.get.__name__ =", msg.get.__name__ )
> > import dis
> > dis.dis( msg.get )
> > dis.show_code( msg.get )
> > 
> Thanks, yes, this tells me a little:-
> 
>     ('msg.get.__doc__ =', 'Get a header value.\n\n        Like
>     __getitem__() but return failobj instead of None when the field\n
>      is missing.\n        ')
> 
> However it isn't mentioned *anywhere* in the documentation that I can
> see.  There's only __getitem__() and get() for the mailbox class which
> operate on a whole mailbox and return a whole message.`
> 
I've worked it out, sort of, by looking at the actual Python code.

The mailbox.mboxMessage() class is a sub-class of email.message and
*that* has the get() function I'm calling.  It does tell you this
in the documentation but it's not immediately obvious.  In particular
one isn't really expecting an object in the mailbox class to be a
sub-class of a different 'parent' class, or at least I wasn't! :-)

-- 
Chris Green
?