Hi Dolph Thank you for your answer.
> I can't get past this specific example... how often do you find yourself > needing to do this, exactly? Generally when you use a list you either FIFO / > LIFO or iterate through the whole thing in some fashion. > > I'd be tempted to write it as dict(enumerate(my_list)).get(3, > 'default_value') just because you're treating it like a mapping anyway. I see this example on the one review which is parsing configuration. so the config looks like key1:val1,key3:val2,:key3:valu3:default >> >> >> This can be also written as, >> >> list_a[3] if len(list_a) > 3 else 'default_value' >> >> "ask for forgiveness, not permission" is one of way in python, >> however, on the other hand, google python code style guide says, >> ------------- >> Minimize the amount of code in a try/except block. The larger the body >> of the try, the more likely that an exception will be raised by a line >> of code that you didn't expect to raise an exception. In those cases, >> the try/except block hides a real error. >> --------------- >> http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Exceptions > > > +1 for this, but it's not really intended to provide an answer your question > of approach. OK, I got it. Best, Nachi >> >> >> >> Personally, I prefer not to use exception for such cases. >> >> Best >> Nachi >> >> _______________________________________________ >> OpenStack-dev mailing list >> [email protected] >> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev > > > > > -- > > -Dolph > > _______________________________________________ > OpenStack-dev mailing list > [email protected] > http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev > _______________________________________________ OpenStack-dev mailing list [email protected] http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
