← index #350Issue #8432
Off-topic · high · value 2.635
QUERY · ISSUE

AttributeError: 'defaultdict' object has no attribute 'items'

openby Xiretzaopened 2019-09-09updated 2024-08-25
>>> from collections import defaultdict
>>> dd = defaultdict(list)
>>> dd
<defaultdict object at 2006e7d0>
>>> dd.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'defaultdict' object has no attribute 'items'

defaultdict doesn't have an items() method, so iterating over it is a bit of a pain in the neck. Also no __repr__(), but that's not totally necessary I guess.

2 comments
Rohith295 · 2021-06-15

Can I work on this issue? @xrmx

jonnor · 2024-08-25

This seems to still be the case - no "items()" function in the defaultdict module.

Anyone is welcomed to open merge requests in the MicroPython project :)

CANDIDATE · ISSUE

AttributeError: 'function' object has no attribute '__name__'

closedby warnerjon12opened 2022-03-20updated 2022-06-24

Some (maybe all) of the builtin functions do not have a __name__ attribute like regular functions:

>>> def f(x):
...     return x
... 
>>> f.__name__
'f'
>>> from math import sin
>>> sin.__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '__name__'

Additionally, micropython does not currently allow assignment/reassignment of function attributes like CPython does:

micropython

>>> f.__name__ = 'g'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '__name__'
>>> f.some_attr = 'some value'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'some_attr'
>>> sin.__name__ = 'g'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '__name__'
>>> sin.some_attr = 'some value'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'some_attr'

CPython

>>> f.__name__ = 'g'
>>> f.some_attr = 'some value'
>>> sin.__name__ = 'g'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: attribute '__name__' of 'builtin_function_or_method' objects is not writable
>>> sin.some_attr = 'some value'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'some_attr'

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied