2017-02-28 3 views
0

python itertools에서 체인의 소스 코드를보고 싶습니다. 그러나 여기에 소스 코드에서 무엇이 있습니까? 왜 그들은 모두 '통과'입니까?python에서 chain의 소스 코드는 어디에 있습니까?

class chain(object): 
    """ 
    chain(*iterables) --> chain object 

    Return a chain object whose .__next__() method returns elements from the 
    first iterable until it is exhausted, then elements from the next 
    iterable, until all of the iterables are exhausted. 
    """ 
    @classmethod 
    def from_iterable(cls, iterable): # real signature unknown; restored from __doc__ 
     """ 
     chain.from_iterable(iterable) --> chain object 

     Alternate chain() contructor taking a single iterable argument 
     that evaluates lazily. 
     """ 
     pass 

    def __getattribute__(self, *args, **kwargs): # real signature unknown 
     """ Return getattr(self, name). """ 
     pass 

    def __init__(self, *iterables): # real signature unknown; restored from __doc__ 
     pass 

    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 

답변

1

본 클래스는 아마도 다른 모듈입니다. Itertools 및 기타 여러 fuctions가 컴파일 된 c로 작성됩니다. 당신은 여기 CPython의 코드 https://github.com/python/cpython/blob/3.6/Modules/itertoolsmodule.c#L1792

를 읽을 수 있고, itertools 설명서에, 그것은에 체인 기능이 거의 비슷 것을 말한다 :

def chain(*iterables): 
    # chain('ABC', 'DEF') --> A B C D E F 
    for it in iterables: 
     for element in it: 
      yield element 
+1

CPython과는 몇 년 동안 SVN의 REPO를 사용하지 않았다. 아마도 [더 현대적인 링크] (https://github.com/python/cpython/blob/3.6/Modules/itertoolsmodule.c#L1792)를 사용 하시겠습니까? – ShadowRanger

+0

링크 해 주셔서 감사합니다. – abccd