Multiple ways to access attributes

Mitya Sirenef msirenef at lightbird.net
Sun Feb 10 18:23:18 EST 2013


On 02/10/2013 05:44 PM, ISE Development wrote:
> Is it considered acceptable  practice (e.g. not confusing, not
 > surprising or not Pythonic) to allow multiple ways to access
 > the same attributes?
 >
 > For example, supposing I am providing access to external
 > devices, that these parameters may vary slightly between
 > devices (e.g. different models, etc...) and that the device
 > may be queried for parameter meta-data (such as name, data
 > type, data value constraints), would the following API be
 > acceptable (in the sense alluded to above)? Or would it be
 > generally considered a distortion of Python idealogy (e.g.
 > like PERL's 'more than one way to do it' approach)?


There should be one-- and preferably only one --obvious way to do it.

The reason for this guideline is that if there were many similar ways to
do the same thing (in the language itself), without one way standing out
as an obvious, idiomatic choice, you would end up with every program
using its own approach and it would be much harder to read and
understand other people's programs. If there's one obvious, preferred
way, you can look at code from hundreds of people and you will know
immediately what they are doing and why.

This does not apply to your case. You are already creating a custom
interface for working with options.

Does your approach make the code more readable and easier to work with?
If yes, this is perfectly fine.

[snip]

  -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Many possessions, if they do not make a man better, are at least expected
to make his children happier; and this pathetic hope is behind many
exertions.  George Santayana




More information about the Python-list mailing list