possible attribute-oriented class

Jan Kaliszewski zuo at chopin.edu.pl
Sun Sep 6 19:37:35 EDT 2009


06-09-2009 o 20:20:21 Ethan Furman <ethan at stoneleaf.us> wrote:

> In the dbf module I wrote, I use both the attribute access and the key  
> lookup.  The attribute access is great for interactive use, and for all  
> the routines that play with the tables we have at work, where all the  
> field names are indeed known at compile (aka coding) time.  On the other  
> hand, some routines don't know which fields they'll mucking about with,  
> and so the key access is vital for them.
>
> Of course, I could have done the whole thing using key access, and I did  
> have to impose some restrictions on method names so they wouldn't clash  
> with possible field names, but I love being able to type
>
>    current_record.full_name == last_record.full_name
>
> instead of
>
>    current_record['full_name'] == last_record['full_name']

Me too, and I suppose many people too...

The latter:

* makes your code less readable if there is high density of such
   expressions;

* makes typing much more strenuous/irritating -- what is not very
   important in case of advanced development (when time of typing is
   short in relation to time of thinking/reading/testing) but becomes
   quite important in case of scripting (which is still important area
   of Python usage).

-- 
Jan Kaliszewski (zuo) <zuo at chopin.edu.pl>



More information about the Python-list mailing list