What is dict?
Duncan Booth
duncan at NOSPAMrcp.co.uk
Tue Aug 13 04:59:57 EDT 2002
martin at v.loewis.de (Martin v. Loewis) wrote in
news:m3eld37jgq.fsf at mira.informatik.hu-berlin.de:
>> What is consensus within the Python community? Is calling dict a
>> function a case of a misnomer?
>
> dict used to be a function, so that is still left over from Python 2.1
> and earlier. I believe there is already a bug report requesting the
> documentation to be corrected - apparently, nobody found it important
> enough so far to actually write a patch to the documentation.
>
Close, but not quite correct.
Most of the types available as builtins: complex, float, int, list, long,
str, tuple, type and unicode were functions in Python 2.1.x and earlier and
have now become type objects whose constructors accept the same arguments
as the functions accepted.
'open' was a function, the 'file' type was added and the open function
became an alias for 'file'.
However, 'dict' did not actually exist at all in 2.1, so if the
documentation says it is a function it is plain wrong, not just out of
date. Perhaps the author felt it was wrong in the lies-to-children[1]
sense, as it is often used as though it were a function.
The other new types to appear in __builtins__ are: classmethod, object,
property, staticmethod and super.
[1] A term coined by Ian Stewart and Jack Cohen in 'The Science of
Discworld' by Terry Pratchett, et al.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list