Implicit lists

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Thu Jan 30 23:03:57 CET 2003


Chirayu Krishnappa <thephoenix235 at gmx.net> wrote:

>I'd like to ask how you get these maybe arg or list things in the
>first place. i presume they are the result of a function call. do you
>have too many such functions? (generally well written function which
>might return a list will return a list even for a single element so
>you can have uniformly written code. the cgi module's FieldStorage
>class' getitem() function is a notable exception.) 
>
>if you find that you need to do this for just a small bunch of
>functions - perhaps you could write wrappers for those functions to
>always return a list and use them instead.
>
>Chirayu.
>
I've considered that but in most situations it is cleaner and more
natural to supply a single arg rather than a list of one item.

For a quickly invented example, consider a database class that accepts
a 'keyField' parameter. In most cases, a single value will suffice.
However some tables need two key values.

dbTable('tblMembers', keyField='memberID')
dbTable('tblPermissions', keyField=('memberID', 'permissionID'))

Turning the first keyField into a single item list (or tuple) looks
untidy.
--
Dale Strickland-Clark
Riverhall Systems Ltd




More information about the Python-list mailing list