Multiple ways to access attributes
ISE Development
isenntp at gmail.com
Sun Feb 10 17:44:54 EST 2013
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)?
class option
-> represents a single option
-> two attributes: info (the parameter meta-data)
value (the parameter getsetter)
class options:
-> represents the device parameter interface
-> provides the following API:
iter(options)
-> iterable through all parameter meta-data
options[0]
-> access parameter 0 meta-data
-> key is integer
options['foo']
-> access parameter 'foo' (returns an 'option' object)
-> key is basestring
-> useful when processing the parameters generically
options.foo
-> same as options['foo']
-> useful for well-known, often used parameters
(really just short-hand for the user)
options.keys()
-> iterator through option names (a specific meta-data
field)
options.values()
-> iterator through option values
options.items()
-> iterator through (name,value) tuples
-- isedev
More information about the Python-list
mailing list