[Tutor] Returning a variable from a module
Paul De Luca
pdeluca@sia.net.au
Mon, 9 Jul 2001 01:13:16 +1000 (EST)
Thanks,
I have used return before but until now have never really
understood what was going on. I tried it first, but I was returning the
config dictionary in the module, then referencing it directly just like
any other variable I had created in the main code.
> for n in range(0, len(configList)):
> configList[n] = string.rstrip(configList[n])
> configList[n] = string.lstrip(configList[n])
> configList[n] = string.replace(configList[n], '\012', '')
>
> Be...
>
> for n in range(0, (len(configList)-1)):
> configList[n] = string.rstrip(configList[n])
> configList[n] = string.lstrip(configList[n])
> configList[n] = string.replace(configList[n], '\012', '')
>
> ?? Either that or I really am poor tonight :)
>
> HTH,
> Glen.
No, range is up to, but not including the last
argument. To quote the docs:
"To iterate over the indices of a sequence, combine range() and len() as
follows:
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
... print i, a[i]
...
0 Mary
1 had
2 a
3 little
4 lamb"
I think we are both really poor tonight ;)