diff --git a/src/bindings/swig/python/examples/example_kdb.py b/src/bindings/swig/python/examples/example_kdb.py index 95a49009adf..8d93e510caf 100644 --- a/src/bindings/swig/python/examples/example_kdb.py +++ b/src/bindings/swig/python/examples/example_kdb.py @@ -7,11 +7,13 @@ db.get(ks, "user/MyApp") # check if key exists - key = ks.lookup("user/MyApp/mykey") - if not key: + try: + key = ks["user/MyApp/mykey"] + except KeyError: # create a new key + append to keyset key = kdb.Key("user/MyApp/mykey") ks.append(key) + # change keys value key.value = "new_value" diff --git a/src/bindings/swig/python/examples/example_keyset.py b/src/bindings/swig/python/examples/example_keyset.py index 723e1e03c64..e0e0e92c520 100644 --- a/src/bindings/swig/python/examples/example_keyset.py +++ b/src/bindings/swig/python/examples/example_keyset.py @@ -29,7 +29,11 @@ print(" KeySet1[1]={0}".format(ks1[1])) print(" KeySet1[-1]={0}".format(ks1[-1])) print(" KeySet1['user/key1']={0}".format(ks1["user/key1"])) -print(" KeySet1['doesnt_exist']={0}".format(ks1["doesnt_exist"])) +try: + print(" KeySet1['doesnt_exist']={0}".format(ks1["doesnt_exist"])) +except KeyError: + print(" KeySet1['doesnt_exist'] throws KeyError") +print(" KeySet1.lookup('doesnt_exist')={0}".format(ks1.lookup("doesnt_exist"))) print("") print("You asked for slices? You get slices:")