本文整理汇总了Python中gnome.utilities.orderedcollection.OrderedCollection.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedCollection.to_dict方法的具体用法?Python OrderedCollection.to_dict怎么用?Python OrderedCollection.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnome.utilities.orderedcollection.OrderedCollection
的用法示例。
在下文中一共展示了OrderedCollection.to_dict方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_int_to_dict
# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import to_dict [as 别名]
def test_int_to_dict(self):
'''added a to_dict() method - test this method for int dtype.
Tests the try, except is working correctly'''
items = range(5)
oc = OrderedCollection(items)
dict_ = oc.to_dict()
assert dict_['dtype'] == int
for (i, item) in enumerate(items):
assert dict_['items'][i][0] \
== '{0}'.format(item.__class__.__name__)
assert dict_['items'][i][1] == i
示例2: test_to_dict
# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import to_dict [as 别名]
def test_to_dict(self):
'added a to_dict() method - test this method'
items = [SimpleMover(velocity=(i * 0.5, -1.0, 0.0)) for i in
range(2)]
items.extend([RandomMover() for i in range(2)])
mymovers = OrderedCollection(items, dtype=Mover)
dict_ = mymovers.to_dict()
assert dict_['dtype'] == mymovers.dtype
for (i, mv) in enumerate(items):
assert dict_['items'][i][0] \
== '{0}.{1}'.format(mv.__module__, mv.__class__.__name__)
assert dict_['items'][i][1] == i
示例3: Model
# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import to_dict [as 别名]
#.........这里部分代码省略.........
"""
(This method satisfies Python's iterator and generator protocols)
:return: the step number
"""
return self.step()
def full_run(self, rewind=True, log=False):
"""
Do a full run of the model.
:param rewind=True: whether to rewind the model first
-- if set to false, model will be run from the
current step to the end
:returns: list of outputter info dicts
"""
if rewind:
self.rewind()
# run the model
output_data = []
while True:
try:
results = self.step()
if log:
print results
output_data.append(results)
except StopIteration:
print "Done with the model run"
break
return output_data
def movers_to_dict(self):
"""
Call to_dict method of OrderedCollection object
"""
return self.movers.to_dict()
def weatherers_to_dict(self):
"""
Call to_dict method of OrderedCollection object
"""
return self.weatherers.to_dict()
def environment_to_dict(self):
"""
Call to_dict method of OrderedCollection object
"""
return self.environment.to_dict()
def spills_to_dict(self):
return self.spills.to_dict()
def outputters_to_dict(self):
"""
Call to_dict method of OrderedCollection object
"""
return self.outputters.to_dict()
def map_to_dict(self):
"""
returns the gnome object type as a string
"""
return "{0}.{1}".format(self.map.__module__, self.map.__class__.__name__)
示例4: Model
# 需要导入模块: from gnome.utilities.orderedcollection import OrderedCollection [as 别名]
# 或者: from gnome.utilities.orderedcollection.OrderedCollection import to_dict [as 别名]
#.........这里部分代码省略.........
:return: the step number
"""
return self.step()
def full_run(self, rewind=True, log=False):
"""
Do a full run of the model.
:param rewind=True: whether to rewind the model first -- defaults to True
if set to false, model will be run from the current
step to the end
:returns: list of outputter info dicts
"""
if rewind:
self.rewind()
# run the model
output_data = []
while True:
try:
results = self.step()
if log:
print results
output_data.append(results)
except StopIteration:
print 'Done with the model run'
break
return output_data
def movers_to_dict(self):
"""
call to_dict method of OrderedCollection object
"""
return self.movers.to_dict()
def environment_to_dict(self):
"""
call to_dict method of OrderedCollection object
"""
return self.environment.to_dict()
def spills_to_dict(self):
return self.spills.to_dict()
def outputters_to_dict(self):
"""
call to_dict method of OrderedCollection object
"""
return self.outputters.to_dict()
def map_to_dict(self):
"""
create a tuple that contains: (type, object.id)
"""
# dict_ = {'map': ("{0}.{1}".format(self.map.__module__, self.map.__class__.__name__), self.map.id)}
return ('{0}.{1}'.format(self.map.__module__,
self.map.__class__.__name__), self.map.id)