dict get
Gives the value at a path of keys.
dict get DICT ?KEY ...?
Description
Gives the value of KEY in DICT. With more than one KEY, each key goes one level down into a nested dict, and the value of the last key is the result. With no KEY it gives DICT as it is, after a check that it is a valid dict.
A missing key is an error. Use dict exists before the call, or dict getdef in Tcl 9.1, for a key that can be missing. A value on the path that is not a dict is an error too.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| DICT | dict | required | The dict. |
| KEY | string | none | A key of the path. |
Returns
The value.
Examples
% dict get {a 1 b 2} b
2
% dict get {a {x 9}} a x
9
% dict get {a 1 b 2}
a 1 b 2
Errors
% dict get {a 1} b
key "b" not known in dictionary
-errorcode NONE
# The value 1 of the key a is not a dict.
% dict get {a 1} a x
missing value to go with key
-errorcode NONE
% dict get
wrong # args: should be "dict get dictionary ?key ...?"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1