Adding keys to key-value dictionary in python

   1410   2   1
User Avatar
Member
13 posts
Joined: Nov. 2013
Offline
Hi,

I was wondering if there's a way to add keys through a loop to a key value dictionary (stored on a null) with python. I got that I can edit keys by hou.parm().set()

But I somehow can't figure out how I would create them. If I run a for loop with an array through set() it would only create and change one key. Could not really find anything in the forum, would be very grateful if sb. could give me a hint

Thanks a mil, cheers
User Avatar
Member
8587 posts
Joined: July 2007
Offline
you can set all values at once using dictionary
values = {'a': '1', 'b': '2', 'c': '3'}
p.set(values)


or to edit/add more keys:
values = p.eval()
values['d'] = '4'
p.set(values)
Edited by tamte - Jan. 19, 2022 12:37:49
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
13 posts
Joined: Nov. 2013
Offline
Hi Tomas, thanks a mil, that worked! Seems like i had my syntax wrong.

Cheers!
  • Quick Links