當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。