function with a lot of parameters --maintainability issue
William Park
parkw at better.net
Tue Oct 31 18:55:01 EST 2000
On Mon, Oct 30, 2000 at 03:30:19PM -0800, First Name Last Name wrote:
> William, thanks for your help. One more quesiton about your solution.
> Since I would like that dictionary to contain a whole set of default values of different types. Can I do something like this:
>
> In file blarblar.py where func is definied, I also define the dictionary.
> That is:
> configDict = {'a': 1, 'b': TRUE, 'c': "Default Val", 'd': "1.245", ...}
>
> def func(sid, args):
> for i in args.keys():
> setVariable(sid, ..., args[i])
>
> In the file that will call the function
> from blarblar import *
>
> def callYou():
> # assume sid is got from somewhere
> newConfigDict = configDict
> # want to change some of the default values
> newconfigDict['a'] = 2
> newConffigDict['b'] = FALSE
> func(sid,newConfigDict)
> ????
Yes, something like that. But, since you already have the dictionary
defined in 'blarblar.py', there is no need to pass it to
'blarblar.func()'. Also, 'newConfigDict' is not necessary.
In 'blarblar.py',
configDict = {'a': 1, 'b': TRUE, ...}
def func(sid):
for i in configDict.keys():
setVariable(sid, ..., configDict[i])
And in your main script,
from blarblar import *
def callYou():
...
configDict['a'] = 2
configDict['b'] = FALSE
func(sid)
> Or I am think should I implement this configDict stuff in a class instead???
Hmm... try dictionary first. Then, when you are comfortable with
Python, then perhaps class. Either will work.
>
> Please help...
> Thanks
---William Park, Open Geometry Consulting
More information about the Python-list
mailing list