Suggest: .get() method on lists.

M.-A. Lemburg mal at lemburg.com
Thu Jan 20 13:34:03 EST 2000


Gerrit Holl wrote:
> 
> Hello,
> 
> What about having a get() method on lists?
> I thought it would be useful, for example, for sys.argv. At the moment,
> I have this code:
> 
> file = sys.stdin
> if len(sys.argv) > 1:
>     file = sys.argv[1]
> 
> But this, would be much easier to read:
> file = sys.argv.get(1, sys.stdin)
> 
> Of course, it's also possible to use multiple inheritance on
> UserList and UserDict creating a DictionairyList for sys.argv,
> because it's the only place I can think of such a feature would
> be a Good Thing (TM).

Check out get() in mxTools (look on my Python Pages for more
infos on that package). It handles all indexable objects...

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/






More information about the Python-list mailing list