Christopher Spears said unto the world upon 2005-12-18 01:30:
> I got my function to work! It takes arguments and
> adds them:
Hi Christopher,
great!
> def adder(**args):
> argsList = args.values()
> sum = argsList[0]
> for x in argsList[1:]:
> sum = sum + x
> r
Christopher Spears wrote:
> I got my function to work! It takes arguments and
> adds them:
>
> def adder(**args):
> argsList = args.values()
> sum = argsList[0]
> for x in argsList[1:]:
> sum = sum + x
> return sum
>
> print adder()
>
> However, if I run the above code.
> def adder(**args):
>argsList = args.values()
>sum = argsList[0]
>for x in argsList[1:]:
>sum = sum + x
>return sum
> line 3, in adder
>sum = argsList[0]
> IndexError: list index out of range
>
> This is caused by the line: print adder(). Obviously
> if adder() doesn
Ed Singleton wrote:
> Is it possible to access the next and previous items during an iteration?
This just came up on c.l.python. Bengt Richter has a nice generator-based
solution.
http://groups.google.com/group/comp.lang.python/browse_thread/thread/2e4533f108fbf172/90d87c91dac844d3?hl=en#90d87c91
On Sun, 18 Dec 2005, Alan Gauld wrote:
> > def adder(**args):
> >argsList = args.values()
> >sum = argsList[0]
> >for x in argsList[1:]:
> >sum = sum + x
> >return sum
>
> > line 3, in adder
> >sum = argsList[0]
> > IndexError: list index out of range
> >
> > This is
> > This is caused by the line: print adder(). Obviously
> > if adder() doesn't receive any arguments, it can't
> > build the lists resulting in an IndexError.
>
> Right.
Hello!
Just wanted to clarify the situation: argsList ends up being the empty
list, which is a perfectly good value:
>> > line 3, in adder
>> >sum = argsList[0]
>> > IndexError: list index out of range
>> >
>> > an IndexError. What is the best way to solve this? Should I write
>> > some syntax into the function to check for arguments?
>>
>> The Pythonic way is to use exceptions.
>
> I disagree for this par
Hello,
I have a few theoric questions regarding name tables. I wish to better
understand a few things about this aspect of Python, in particular how
module names and the import statements fit into the picture of name
tables.
- First of all, I understand each scope has its "local" name table,
cont