2014-10-28 8 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) 

Notare il due parametri nella prima riga della docstring.Che cos'è il "modulo" nella docstring di len?

Quando passare due argomenti a len? La docstring è errata? Sto usando Python 3.4.0.

+2

Per me, 'stampa (len .__ doc __)' stampe ** len (oggetto) ritorno il numero di elementi di una sequenza o collezione. ** – falsetru

+0

@falsetru È strano. Quale versione di Python usi? – rightfold

+0

Sto usando Python 3.4.2 – falsetru

risposta

9

Questo era un bug inviato il 2014-04-18 here. Da allora è stato risolto in 3.4.1.

Citando Vedran Čačić, l'autore originale del bug report:

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) contiene anche due argomenti nella docstring di 'len()', ma la docstring è leggermente diversa e l'oggetto modulo non viene usato affatto. –

Problemi correlati