python map 的用法

                                    map的用法

——、我们来分析map在python的源码

class map(object):
"""
map(func, *iterables) --> map object
Make an iterator that computes the function using arguments from
利用来自可迭代的每个参数,来计算迭代的函数,当短的可迭代的参数耗尽,程序停止
each of the iterables. Stops when the shortest iterable is exhausted.
"""
def __getattribute__(self, *args, **kwargs): # real signature unknown
""" Return getattr(self, name). """
pass
getattribute(字面意思是:获取属性)
在python中的用法,
  

__getattribute__是访问属性的方法,我们可以通过方法重写来扩展方法的功能。

对于python来说,属性或者函数都可以被理解成一个属性,且可以通过__getattribute__获取。

当获取属性时,直接return object.__getattribute__(self, *args, **kwargs)

如果需要获取某个方法的返回值时,则需要在函数后面加上一个()即可。如果不加的话,返回的是函数引用地址。见下方代码


def __init__(self, func, *iterables): # real signature unknown; restored from __doc__
pass
这里是初始 map的函数要传入的值,两个值一个是函数,一个是可迭代的对象
def __iter__(self, *args, **kwargs): # real signature unknown
""" Implement iter(self). """
pass
把可迭代的对象变成迭代器的对象
@staticmethod # known case of __new__
def __new__(*args, **kwargs): # real signature unknown
""" Create and return a new object. See help(type) for accurate signature. """
pass
def __next__(self, *args, **kwargs): # real signature unknown
""" Implement next(self). """
pass
def __reduce__(self, *args, **kwargs): # real signature unknown
""" Return state information for pickling. """
pass