Keyvalues.KeyValues
From EventScripts Community Encyclopedia
|
[edit] Class: keyvalues.KeyValuesNote: Requires EventScripts 2.0
Module: keyvalues [edit] Overview[edit] DescriptionThis is a wrapper class for Valve's C++ KeyValues class. It is basically a tree-based datastructure where every node has a name and a value. [edit] Quick Exampleimport keyvalues k = keyvalues.KeyValues(name="top") k['myvalue'] = 'hello' k['mysubkey'] = keyalues.KeyValues(name='mysubkey') k['mysubkey']['mysubvalue'] = 99 k.save('/tmp/mykeyfile.txt') [edit] Methods__init__(name=None, parent=None, existingid=None, filename=None) (i.e. the constructor) You can create a new KeyValues object by passing in different combinations of arguments: With only an existingid, KeyValues returns a wrapper around that existing id (i.e. C++ pointer). With only a parent, we'll create a new randomly named subkey. With a parent and name, we'll find/make a subkey of that name. With a name only, we'll create an unparented key with that name. With a filename, we'll load the KeyValues tree from disk and return it as the parent. .load(filename) Loads this KeyValue's contents from a file. .save(filename) Save this KeyValue's contents to a file. .getParent() Returns the parent KeyValues class to this one. .keys() Returns a list of top-level subkeys. __getitem__(name) (i.e. dictionary-style lookup) Look up a value by name, a lot like a dictionary. Can return a value or a subkey, depending on what is returned. __setitem__(self, name, value) (i.e. dictionary-style storing) Stores a name/value pair in the keygroup. Only ints, floats, strings, and KeyValues classes (as subkeys) can be stored. getName() Returns the key's name getString(valname) Returns directly a typed version of the key's value for that value name. __iter__() (i.e. list-style iteration) Allows you to loop through the KeyValues class subkeys in a for x in mykey: command. [edit] Attributes{{{attributes}}} [edit] Notes
[edit] See Also |
|
