Quote:
> I just stumbled across this (with several changes to remove
> unimportant details):
> def someFunct(arg):
> print "the arg is ", arg
> rawlist = os.listdir(arg)
> qualified = map( lambda x: os.path.join(arg,x), rawlist)
> The problem is in the lambda function, and it's a NameError: arg.
> I was wondering what the general rule is on scoping and lambdas.
The problem is that arg is not in scope inside the lambda. To
fix it, add the default argument "arg=arg" inside your lambda like this:
def someFunct(arg):
print "the arg is ", arg
rawlist = os.listdir(arg)
qualified = map( lambda x,arg=arg: os.path.join(arg,x), rawlist)
ps- lambdas are really slow if you pass python functions as the
argument. try a for-list instead.
Quote:
> I'm sure that it's just a fundamental newbie problem, but in
> case it helps, I'm using PythonWin 1.4.
> Tim
welcome- dave m.
Quote:
> p.s: What a cool little language!