[Tutor] non-typed variables AND naming conventions
Stephan Richter
srichter@cbu.edu
Mon, 04 Dec 2000 21:55:41 -0600
>most of my work has not needed a variable to be loosely typed, it is just a
>flexibility gain.
Well, here an example that Zope uses (code untested):
When I call a function I have a optional parameter that can be a lsit of
strings or if I just have one element a single string. In this case it
would like this:
def getValues(keys=[]):
dict = {'a': 1, 'b': 2, 'c':3}
if type(keys).__name__ == 'string':
return (dict[keys],)
else:
help = ()
for key in keys:
help = help + (dict[key],)
return help
Both times the function will return a tuple. so the function really does
not care whether keys ends up being a string or a list.
Regards,
Stephan
--
Stephan Richter
CBU - Physics and Chemistry Student
Web2k - Web Design/Development & Technical Project Management