2017-02-28 5 views
0

私はpython itertoolsのチェーンのソースコードを見たいと思いますが、ここで私はソースコードで何を見つけるのですか?なぜ彼らはすべて「合格」ですか?pythonのチェーンのソースコードはどこですか?

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、および他の多くの機能がコンパイルされたcで書かれています。あなたはここに https://github.com/python/cpython/blob/3.6/Modules/itertoolsmodule.c#L1792

をCPythonのコードを読むことができると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のレポを使用していません。おそらくもっと最近のリンク(https://github.com/python/cpython/blob/3.6/Modules/itertoolsmodule.c#L1792)を使ってください。 – ShadowRanger

+0

リンクありがとうございます – abccd

関連する問題