python变量未定义_python – lambda函数中的未定义变量

我有代码:

from functools import reduce

public_ids = [1,2,3,4,5]

filepath = '/path/to/file/'

rdd = sc.textFile(

filepath

)

new_rdd = reduce(

lambda a, b: a.filter(

lambda x: b not in x

),

public_ids,

rdd

)

此代码假定根据id列表过滤rdd中的行. rdd是使用spark context sc的textFile方法从位于filepath中的文件创建的.

此代码工作正常,但是pylint会引发错误:

E: Undefined variable ‘b’ (undefined-variable)

我相信我编码它的方式不是正确的方法.如何更改它,以便pylint不会再次引发错误?或者它只是一个结构,pylint无法正确识别?

最佳答案 很可能这是pylint中的一个错误.

foo = lambda x: lambda: x + 1 print(foo(1)())

correctly prints 2 when run, but pylint incorrectly reports

E: 1,24: Undefined variable 'x' (undefined-variable)

This is a regression from pylint 1.4.x.

这是一个recent issue在11/14/2018报道同一个问题

The issue has been reported at #760 and fixed by #2274. However, the

fix is merged only into pylint 2.x which supports only python >= 3.4

leaving us with the bug unresolved in the pylint 1.x series for python

2.

编辑

看起来你的误报可能与上面的问题略有不同,但是,我仍然认为这是一个错误.

我会尝试在他们的回购中创建一个问题,看看会发生什么

(如果您决定这样做,请在评论中发布链接,以便我们可以关注它.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值