Method |
Description |
keys() |
Returns a list of the keys in the repository. |
has_key() |
Returns 1 if the key is found in the repository; otherwise,
returns 0. |
values() |
Returns a list of the objects in the repository. |
items() |
Returns a list of key, value pairs in the repository. |
changeKey(fromName,
toName) |
Changes the name of a key in the repository. This method will also change the name attribute of the instance in the repository. |
The following script illustrates some of these methods:
from customKernel
import CommandRegister
class Block(CommandRegister):
def __init__(self, name):
CommandRegister.__init__(self)
mdb.customData.Repository('blocks', Block)
mdb.customData.Block(name='Block-1')
mdb.customData.Block(name='Block-2')
print 'The original repository keys are: ',
mdb.customData.blocks.keys()
print mdb.customData.blocks.has_key('Block-2')
print mdb.customData.blocks.has_key('Block-3')
mdb.customData.blocks.changeKey('Block-1', 'Block-11')
print 'The modified repository keys are: ',
mdb.customData.blocks.keys()
print 'The name member is ',
mdb.customData.blocks['Block-11'].name
print 'The repository size is', len(mdb.customData.blocks)
The resulting output is
The original repository keys are ['Block-1', 'Block-2']
1
0
The modified repository keys are ['Block-11', 'Block-2']
The name member is Block-11
The repository size is 2