Ah, there is a functional difference but when I reference the anticipated content of the rows object I would raise an exception anyway.
I check rows before using it. I guess #1 is a bit clearer. Thank you. On Saturday, December 8, 2012 12:20:36 PM UTC-8, Lewis wrote: > > Which syntax is preferred, and if so, why? > > syntax 1: rows[0]['auth_user.first_name'] > syntax 2: rows.first().auth_user.first_name > > 1 seems closer to common Python syntax and is likely more interpretable to > any Python programmer. 2 seems a bit more readable but relies on knowing > the DAL methods and seems a bit ad hoc. > > Is this a third: rows[0].['auth_user']['first_name']? This would seem > the most consistent with Python dictionary referencing syntax. > > And I could have added .as_list() to my initial query and a;sp used the > third syntax. This is of course doing something different by serializing > the row into a real Python dictionary and losing the db affinity. > > In general, web2py seems to have a few too many alternative ways to do the > same thing, which are a bit of syntactic sugar or ways to save a few > characters of typing. Neither seem like good reasons... Multiple ways to > do the same thing (when, indeed it is the "same") seems confusing, > especially if some of the variants only work in certain cases. Best to > have one way that always works... Of course, I am free to use the "basic" > way and others can use the variants. > > Web2py is working great and I ask only to clean up my code (most of the > problems are very much mine!). > > Thanks. > --

