[Tutor] Question about large numbers of arguments

Alan Gauld alan.gauld at freenet.co.uk
Wed Apr 5 13:34:17 CEST 2006


> Suppose you have a situation where you have a large number of command-line
> options that you will parse with getopt.  You want to keep track of these
> as you move around in the code and do various things.
>
> Is it more Pythonic to:
>
> Have the functions take large numbers of parameters.
>
> Create an options class to pass the options around.

Neither, the most Pythonic way IMHO is to use a dictionary and
possibly combine with Pythons variable arguments syntax as
described in section 4.7.3/4 of the official tutor.

> I personally think the latter would look a lot cleaner once the number of
> options got up to around a half dozen, but I usually see the "large number
> of parameters" style in other people's code.

Classes without behaviour are really just glorified dictionaries so
I prefer to use a dictionary. The **args mechanism provides a
good way to pass these to functions.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list