Skip to content

Commit acb5d84

Browse files
authored
[configlet] Python3 compatible syntax for extracting a key from the dict (sonic-net#1721)
Signed-off-by: Neetha John <[email protected]> Syntax error seen while trying to apply a configlet Traceback (most recent call last): File "/usr/local/bin/configlet", line 212, in main() File "/usr/local/bin/configlet", line 205, in main process_entry (do_update, i) File "/usr/local/bin/configlet", line 175, in process_entry do_operate(op_upd, t, (), data[t]) File "/usr/local/bin/configlet", line 162, in do_operate if type(lst[lst.keys()[0]]) == dict: TypeError: 'dict_keys' object is not subscriptable What I did Use next(iter()) to derive a key from the dict. This is both python2 and python3 compatible How to verify it Tried applying the json file below using the command 'configlet -j test.json -d'. Configlet was applied successfully. No errors were seen [ { "ACL_TABLE": { "EVERFLOW": {}, "EVERFLOWV6": {} } } ]
1 parent 9b7c58b commit acb5d84

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

scripts/configlet

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def do_delete(t, k, lst):
159159

160160
def do_operate(op_upd, t, k, lst):
161161
if lst:
162-
if type(lst[lst.keys()[0]]) == dict:
162+
if type(lst[next(iter(lst))]) == dict:
163163
for i in lst:
164164
do_operate(op_upd, t, k+(i,), lst[i])
165165
return

0 commit comments

Comments
 (0)