Re: Fail saving a namedtuple by Pickle


Javi Domínguez
 

Thank you.

I think that's the key. The first argument, the class name, must be the same as the variable to which it is assigned the return of collection.namedtuple.

ThisClassName = collections.namedtuple("ThisClassName", ...

Great, so it seems to work.

Greetings

Javi Dominguez

El 17/05/2020 a las 18:45, Noelia Ruiz escribió:
I am not sure but I'm curious too. Mesar started using namedtuple in
Emoticons add-on, coauthored by him (main author Chris).
Maybe a syntax error?

I don't have your repo, but maybe fixed using

NavKeys = collections.namedtuple('NavKeys', 'nextOption previousOption
nextItem previousItem')

https://pymotw.com/2/collections/namedtuple.html#

2020-05-17 17:32 GMT+02:00, Javi Domínguez <fjavids@...>:
Hello.

Does anyone know why this error occurs? Nothing happens, I easily fix it
by converting it to normal list before saving but i would like to
understand the cause of the failure.

NavKeys = collections.namedtuple("NavigationKeys", ("nextOption",
"previousOption", "nextItem", "previousItem"))
self.navKeys = NavKeys("kb:rightArrow", "kb:leftArrow",
"kb:downArrow", "kb:upArrow")
ERROR - unhandled exception (17:10:15.027) - MainThread (10756):
Traceback (most recent call last):
  File "gui\settingsDialogs.pyc", line 623, in onOk
  File "gui\settingsDialogs.pyc", line 617, in _doSave
  File
"C:\Users\Javichi\AppData\Roaming\nvda\addons\easyNavigation\globalPlugins\easyNavigation\__init__.py",

line 216, in onSave
    easyNavigationRing.save()
  File
"C:\Users\Javichi\AppData\Roaming\nvda\addons\easyNavigation\globalPlugins\easyNavigation\__init__.py",

line 86, in save
    pickle.dump((ring, self.defaultActive, self.navKeys), f, 0)
_pickle.PicklingError: Can't pickle <class
'globalPlugins.easyNavigation.NavigationKeys'>: attribute lookup
NavigationKeys on globalPlugins.easyNavigation failed
Thanks

Javi Dominguez





Join nvda-addons@nvda-addons.groups.io to automatically receive all group messages.