Cool object trick
Steve Holden
steve at holdenweb.com
Fri Dec 17 08:43:12 EST 2004
Doran_Dermot at emc.com wrote:
> I rather like it! I prefer writing obj.spam to obj["spam"]! I wonder if
> there is a technical downside to this use of Python?
>
> P.S.
>
> Certainly makes writing 'print obj.spam, obj.spam, obj.eggs, obj.bacon,
> obj.sausages, "and", obj.spam' a lot easier ;-)
>
Of course this whole thing of substituting attribute access for
dictionary keys only works as long as the keys are strings with the same
syntax as Python identifiers, so one shouldn't go completely overboard.
"To the man with a hammer everything looks like a nail", and so on.
regards
Steve
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
More information about the Python-list
mailing list