[Tutor] special attributes naming confusion
Dave
davestechshop at gmail.com
Wed Jun 6 21:47:09 CEST 2012
On Wed, Jun 6, 2012 at 3:30 PM, Prasad, Ramit <ramit.prasad at jpmorgan.com>wrote:
> > My question is how was I supposed to kinow that the function I call
> using the
> > name iter() is implemented using the name __iter__()?
> >
> > Is there a rule that describes when I would implement an attribute name
> with
> > leading and trailing double underscores, and then call it without those
> > underscores? How many names like this exist in Python? Are these special
> cases
> > or is there a general rule that leading and trailing double underscores
> get
> > dropped when calling functions that were implemented with these names?
> I'm
> > trying to understand the big picture as far as how Python works when it
> comes
> > to this situation. Thanks.
>
> They are listed here
> http://docs.python.org/reference/datamodel.html#specialnames
>
> Ramit
>
>
Thank you. That's a good start. It appears to answer half my question. It
tells me about special names like __new__, __init__, etc. And there is also
mention of __iter__(self) on that page too. But I don't see any discussion
of the convention regarding mappings from those names to the typical names
used to call the functions in code. Unless I'm overlooking it, that page
doesn't explain how to generalize the above example where calling the
function by the name iter() actually calls the implementation named
__iter__(). Are the leading and trailing double underscores simply dropped
always? (It doesn't seem that simple because functions like __init__ are
called behind the scenes.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120606/0586bb77/attachment.html>
More information about the Tutor
mailing list