Adding keys to key-value dictionary in python

   2993   2   1
User Avatar
Member
13 posts
Joined: 11月 2013
オフライン
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
9372 posts
Joined: 7月 2007
オフライン
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 - 2022年1月19日 12:37:49
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
13 posts
Joined: 11月 2013
オフライン
Hi Tomas, thanks a mil, that worked! Seems like i had my syntax wrong.

Cheers!
  • Quick Links