2014-10-28 15 views
6
>>> print(len.__doc__) 
len(module, object) 

Return the number of items of a sequence or mapping. 
>>> len(os, 1) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: len() takes exactly one argument (2 given) 

Zauważ parametry dwa w pierwszym wierszu docstringu.Co to jest "moduł" w docstringie len?

Kiedy przekażesz dwa argumenty do len? Czy docstring jest nieprawidłowy? Używam Pythona 3.4.0.

+2

Dla mnie 'print (len .__ doc __)' odbitki ** len (Object) Zwraca liczbę elementów w sekwencji lub kolekcja. ** – falsetru

+0

@falsetru To dziwne. Z której wersji Pythona korzystasz? – rightfold

+0

Używam Pythona 3.4.2 – falsetru

Odpowiedz

9

To był błąd zgłoszony 2014-04-18 here. Zostało to naprawione w 3.4.1.

Cytowanie Vedran Cacic, oryginalny autor raportu o błędzie:

From recently, help(len) gives the wrong signature of len. 

Help on built-in function len in module builtins: 

len(...) 
    len(module, object) 
     ^^^^^^^^ 
    Return the number of items of a sequence or mapping. 
+1

[Python 3.5.0 alpha 1] (https://github.com/python/cpython/blob/master/Python/bltinmodule.c#L1836) zawiera również dwa argumenty w docenowaniu 'len()', ale docstring jest nieco inny, a obiekt modułu w ogóle nie jest używany. –