[New-bugs-announce] [issue26613] Descriptor HowTo Guide - Typo
Stubz
report at bugs.python.org
Tue Mar 22 20:56:24 EDT 2016
New submission from Stubz:
The last line has a typo ... Dict.fromkeys -> dict.fromkeys
I am a newbie, but that was just a pain in the ass ...
Worked my way thru this How to and spent an hour+ trying to sort a circular argument error...
Was this intentional ¿
In as much as it was a pain in the ass, I think I got the concept sorted ...
https://docs.python.org/3.5/howto/descriptor.html
Static Methods and Class Methods
This behavior is useful whenever the function only needs to have a class reference and does not care about any underlying data. One use for classmethods is to create alternate class constructors. In Python 2.3, the classmethod dict.fromkeys() creates a new dictionary from a list of keys. The pure Python equivalent is:
class Dict(object):
. . .
def fromkeys(klass, iterable, value=None):
"Emulate dict_fromkeys() in Objects/dictobject.c"
d = klass()
for key in iterable:
d[key] = value
return d
fromkeys = classmethod(fromkeys)
Now a new dictionary of unique keys can be constructed like this:
>>>
Dict.fromkeys('abracadabra')
----------
assignee: docs at python
components: Documentation
messages: 262223
nosy: docs at python, stubzpub
priority: normal
severity: normal
status: open
title: Descriptor HowTo Guide - Typo
type: behavior
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26613>
_______________________________________
More information about the New-bugs-announce
mailing list