Quote:
Originally Posted by capink
I was just not sure it is OK to add non string values to the globals dict. Otherwise, I'm fine with using the globals dict for this purpose. This would make my newly added "Run Python Code" action obsolete, and I can phase it out.
|
I thought I better test putting arbitrary things in globals.
This template works:
Code:
python:
def evaluate(self, **kwargs):
mi = kwargs['book']
db = kwargs['db']
g = kwargs['globals']
v = g.get('_mything', dict())
v['someting'] = {1,2,3,4}
g['_mything'] = v
print(g)
print(mi.authors)
print('aaa', db.path(mi.id, index_is_id=True))
s = self.get_default_if_none(mi, 'series', '**no series**')
return s + ':::' + str(self.get_default_if_none(mi, '#myint', 999))
def get_default_if_none(self, mi, field, default):
v = mi.get(field, None)
return default if v is None else v
It prints
Code:
{'_mything': {'someting': {1, 2, 3, 4}}}
['The 10 Angry Men']
aaa The 10 Angry Men\_Unknown_ (1444)
The first line shows that globals['_mything'] contains a dict containing a set.