当前位置: 首页>>代码示例>>Python>>正文


Python OrderedCollection.to_dict方法代码示例

本文整理汇总了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
开发者ID:kthyng,项目名称:GNOME2,代码行数:14,代码来源:test_ordered_collection.py

示例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
开发者ID:kthyng,项目名称:GNOME2,代码行数:16,代码来源:test_ordered_collection.py

示例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__)
开发者ID:kthyng,项目名称:GNOME2,代码行数:69,代码来源:model.py

示例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)
开发者ID:JamesMakela,项目名称:GNOME2,代码行数:70,代码来源:model.py


注:本文中的gnome.utilities.orderedcollection.OrderedCollection.to_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。