[Tutor] special attributes naming confusion

Prasad, Ramit ramit.prasad at jpmorgan.com
Wed Jun 6 23:23:50 CEST 2012


> For instance, the __iter__() method is called by the iter() built-in.
> It can also called by any other piece of code that needs to acquire an
> iterator from a generic container object.  There is no list of all
> such pieces of code that could ever call the __iter__() method of your

A lot of times iter()/__iter__() are used implicitly and not explicitly.
So knowing that iter() specifically calls __iter__ is not as useful as
knowing *when* to implement __iter__(). For example,

for x in obj: 
    # this is an implicit call; works for collections or instance that 
    # implements __iter__()
    pass


Knowing when the special methods are used is more important than 
knowing the "mapping" or what built-in calls it. Most of the times
I do not even use built-ins like iter() explicitly--the exception being
len().

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  


More information about the Tutor mailing list