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


Python _compact.OrderedDict类代码示例

本文整理汇总了Python中_compact.OrderedDict的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict类的具体用法?Python OrderedDict怎么用?Python OrderedDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OrderedDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_book_from_book_dict

 def test_get_book_from_book_dict(self):
     content = OrderedDict()
     content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
     content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
     content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
     book = pe.get_book(bookdict=content)
     assert book.to_dict() == content
开发者ID:bdeeney,项目名称:pyexcel,代码行数:7,代码来源:test_signature_fuction.py

示例2: setUp

class TestCSVNXlsMultipleSheets:
    def setUp(self):
        self.testfile = "multiple1.csv"
        self.content = OrderedDict()
        self.content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
        self.content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
        self.content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
        pe.save_book_as(dest_file_name=self.testfile, bookdict=self.content)

    def test_read_multiple_csv_into_book(self):
        book = pe.load_book(self.testfile)
        assert book.sheet_names() == ["Sheet1", "Sheet2", "Sheet3"]
        book["Sheet1"].format(int)
        assert self.content["Sheet1"] == book["Sheet1"].to_array()
        book["Sheet2"].format(int)        
        assert self.content["Sheet2"] == book["Sheet2"].to_array()
        book["Sheet3"].format(int)        
        assert self.content["Sheet3"] == book["Sheet3"].to_array()

    def tearDown(self):
        if os.path.exists("multiple1__Sheet1__0.csv"):
            os.unlink("multiple1__Sheet1__0.csv")
        if os.path.exists("multiple1__Sheet2__1.csv"):
            os.unlink("multiple1__Sheet2__1.csv")
        if os.path.exists("multiple1__Sheet3__2.csv"):
            os.unlink("multiple1__Sheet3__2.csv")
开发者ID:dardevelin,项目名称:pyexcel,代码行数:26,代码来源:test_multiple_sheets.py

示例3: test_get_book_from_sql

 def test_get_book_from_sql(self):
     book_dict = pe.get_book_dict(session=Session(),
                                  tables=[Signature, Signature2])
     expected = OrderedDict()
     expected.update({'signature': [['X', 'Y', 'Z'], [1, 2, 3], [4, 5, 6]]})
     expected.update({'signature2': [['A', 'B', 'C'], [1, 2, 3], [4, 5, 6]]})
     assert book_dict == expected
开发者ID:dardevelin,项目名称:pyexcel,代码行数:7,代码来源:test_signature_fuction.py

示例4: test_save_book_to_memory_from_sql

 def test_save_book_to_memory_from_sql(self):
     test_file = pe.save_book_as(dest_file_type="xls", session=Session(), tables=[Signature, Signature2])
     book_dict = pe.get_book_dict(file_content=test_file.getvalue(), file_type="xls")
     expected = OrderedDict()
     expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
     expected.update({"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]})
     assert book_dict == expected
开发者ID:bdeeney,项目名称:pyexcel,代码行数:7,代码来源:test_signature_fuction.py

示例5: setUp

class TestBook:
    def setUp(self):
        self.content = OrderedDict()
        self.content.update({"Sheet1": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
        self.content.update({"Sheet2": [[u'A', u'B', u'C'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
        self.result1 = [{'Y': 4, 'X': 1, 'Z': 7}, {'Y': 5, 'X': 2, 'Z': 8}, {'Y': 6, 'X': 3, 'Z': 9}]
        self.result2 = [{'B': 4, 'A': 1, 'C': 7}, {'B': 5, 'A': 2, 'C': 8}, {'B': 6, 'A': 3, 'C': 9}]

    def test_book_save_to_models(self):
        model1=FakeDjangoModel()
        model2=FakeDjangoModel()
        book = pe.Book(self.content)
        book.save_to_django_models([model1, model2])
        assert model1.objects.objs == self.result1
        assert model2.objects.objs == self.result2

    def test_model_save_to_models(self):
        model=FakeDjangoModel()
        pe.save_book_as(dest_models=[model, None, None], bookdict=self.content)
        assert model.objects.objs == self.result1

    def test_load_book_from_django_model(self):
        model=FakeDjangoModel()
        book = pe.Book(self.content)
        book.save_to_django_models([model])
        assert model.objects.objs == self.result1
        model._meta.update(["X", "Y", "Z"])
        book2 = pe.get_book(models=[model])
        assert book2[0].to_array() == book[0].to_array()
        
    def test_more_sheets_than_models(self):
        self.content.update({"IgnoreMe":[[1,2,3]]})
        model=FakeDjangoModel()
        pe.save_book_as(dest_models=[model], bookdict=self.content)
        assert model.objects.objs == self.result1
开发者ID:CHEN-JIANGHANG,项目名称:pyexcel,代码行数:35,代码来源:test_django_related_functions.py

示例6: test_get_book_from_file_stream

 def test_get_book_from_file_stream(self):
     content = OrderedDict()
     content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
     content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
     content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
     io = pe.save_book_as(dest_file_type="xls", bookdict=content)
     book2 = pe.get_book(file_stream=io, file_type="xls")
     assert book2.to_dict() == content
开发者ID:dardevelin,项目名称:pyexcel,代码行数:8,代码来源:test_signature_fuction.py

示例7: test_get_book_dict

 def test_get_book_dict(self):
     content = OrderedDict()
     content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
     content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
     content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
     io = pe.save_book_as(dest_file_type="xls", bookdict=content)
     adict = pe.get_book_dict(file_content=io.getvalue(), file_type="xls")
     assert adict == content
开发者ID:bdeeney,项目名称:pyexcel,代码行数:8,代码来源:test_signature_fuction.py

示例8: test_pyexcel_xls_issue_2

def test_pyexcel_xls_issue_2():
    data = OrderedDict()
    array = []
    for i in range(4100):
        array.append([datetime.datetime.now()])
    data.update({"test": array})
    save_data("test.xls", data)
    os.unlink("test.xls")
开发者ID:pyexcel,项目名称:pyexcel-xls,代码行数:8,代码来源:test_bug_fixes.py

示例9: test_get_book_from_memory_compatibility

 def test_get_book_from_memory_compatibility(self):
     content = OrderedDict()
     content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
     content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
     content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
     io = pe.save_book_as(dest_file_type="xls", bookdict=content)
     book2 = pe.get_book(content=io.getvalue(), file_type="xls")
     assert book2.to_dict() == content
开发者ID:bdeeney,项目名称:pyexcel,代码行数:8,代码来源:test_signature_fuction.py

示例10: test_issue_10

 def test_issue_10(self):
     thedict = OrderedDict()
     thedict.update({"Column 1": [1,2,3]})
     thedict.update({"Column 2": [1,2,3]})
     thedict.update({"Column 3": [1,2,3]})
     pe.save_as(adict=thedict, dest_file_name="issue10.xls")
     newdict = pe.get_dict(file_name="issue10.xls")
     assert isinstance(newdict, OrderedDict) == True
     assert thedict == newdict
开发者ID:CHEN-JIANGHANG,项目名称:pyexcel,代码行数:9,代码来源:test_bug_fixes.py

示例11: test_save_book_as_file_from_sql

 def test_save_book_as_file_from_sql(self):
     test_file = "book_from_sql.xls"
     pe.save_book_as(out_file=test_file, session=Session(), tables=[Signature, Signature2])
     book_dict = pe.get_book_dict(file_name=test_file)
     expected = OrderedDict()
     expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
     expected.update({"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]})
     assert book_dict == expected
     os.unlink(test_file)
开发者ID:bdeeney,项目名称:pyexcel,代码行数:9,代码来源:test_signature_fuction.py

示例12: test_save_book_as_file_from_sql

 def test_save_book_as_file_from_sql(self):
     test_file="book_from_sql.xls"
     pe.save_book_as(out_file=test_file,
                     session=Session(),
                     tables=[Signature, Signature2])
     book_dict = pe.get_book_dict(file_name=test_file)
     expected = OrderedDict()
     expected.update({'signature': [['X', 'Y', 'Z'], [1, 2, 3], [4, 5, 6]]})
     expected.update({'signature2': [['A', 'B', 'C'], [1, 2, 3], [4, 5, 6]]})
     assert book_dict == expected
     os.unlink(test_file)
开发者ID:dardevelin,项目名称:pyexcel,代码行数:11,代码来源:test_signature_fuction.py

示例13: test_get_book_from_file

 def test_get_book_from_file(self):
     test_file = "test_get_book.xls"
     content = OrderedDict()
     content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
     content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
     content.update({"Sheet3": [[u"X", u"Y", u"Z"], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
     book = pe.Book(content)
     book.save_as(test_file)
     book2 = pe.get_book(file_name=test_file)
     assert book2.to_dict() == content
     os.unlink(test_file)
开发者ID:bdeeney,项目名称:pyexcel,代码行数:11,代码来源:test_signature_fuction.py

示例14: test_tutorial05_example3

 def test_tutorial05_example3(self):
     content="Column 1,Column 2,Column 3\n1,4,7\n2,5,8\n3,6,9"
     reader = pe.SeriesReader(("csv", content))
     print(reader.column["Column 3"]) 
     extra_data = OrderedDict()
     extra_data.update({"Column 4":[10, 11, 12]})
     extra_data.update({"Column 5":[13, 14, 15]})
     reader.column += extra_data
     print(pe.utils.to_dict(reader))
     assert reader.column["Column 4"] == [10, 11, 12]
     assert reader.column["Column 5"] == [13, 14, 15]
开发者ID:bdeeney,项目名称:pyexcel,代码行数:11,代码来源:test_examples.py

示例15: TestXlsNXlsmMultipleSheets

class TestXlsNXlsmMultipleSheets(PyexcelMultipleSheetBase):
    def setUp(self):
        self.testfile = "multiple1.xls"
        self.testfile2 = "multiple1.xlsm"
        self.content = OrderedDict()
        self.content.update({"Sheet1": [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]})
        self.content.update({"Sheet2": [[4, 4, 4, 4], [5, 5, 5, 5], [6, 6, 6, 6]]})
        self.content.update({"Sheet3": [[u'X', u'Y', u'Z'], [1, 4, 7], [2, 5, 8], [3, 6, 9]]})
        self._write_test_file(self.testfile)

    def tearDown(self):
        self._clean_up()
开发者ID:dardevelin,项目名称:pyexcel,代码行数:12,代码来源:test_multiple_sheets.py


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