python

python模块之six

2020-06-13  本文已影响0人  wit92

代码案例

python3中使用python2的模块

Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> reduce
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'reduce' is not defined
>>> from six.moves import reduce
>>> def add(x, y):
...     return x+y
... 
>>> reduce(add,[1,2,3,4,5,6])
21
>>> reduce(lambda x ,y:x+y,[1,2,3,4,5])
15

上一篇 下一篇

猜你喜欢

热点阅读