Python csv.unregister_dialect方法代码示例

本文整理汇总了Python中csv.unregister_dialect方法的典型用法代码示例。如果您正苦于以下问题:Python csv.unregister_dialect方法的具体用法?Python csv.unregister_dialect怎么用?Python csv.unregister_dialect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块csv的用法示例。

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

示例1: test_registry_badargs

# 需要导入模块: import csv [as 别名]
# 或者: from csv import unregister_dialect [as 别名]
def test_registry_badargs(self):
        self.assertRaises(TypeError, csv.list_dialects, None)
        self.assertRaises(TypeError, csv.get_dialect)
        self.assertRaises(csv.Error, csv.get_dialect, None)
        self.assertRaises(csv.Error, csv.get_dialect, "nonesuch")
        self.assertRaises(TypeError, csv.unregister_dialect)
        self.assertRaises(csv.Error, csv.unregister_dialect, None)
        self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch")
        self.assertRaises(TypeError, csv.register_dialect, None)
        self.assertRaises(TypeError, csv.register_dialect, None, None)
        self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0)
        self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
                          badargument=None)
        self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
                          quoting=None)
        self.assertRaises(TypeError, csv.register_dialect, []) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_csv.py


示例2: test_dialect_str

# 需要导入模块: import csv [as 别名]
# 或者: from csv import unregister_dialect [as 别名]
def test_dialect_str(self):
        data = """\
fruit:vegetable
apple:brocolli
pear:tomato
"""
        exp = DataFrame({
            'fruit': ['apple', 'pear'],
            'vegetable': ['brocolli', 'tomato']
        })
        csv.register_dialect('mydialect', delimiter=':')
        with tm.assert_produces_warning(ParserWarning):
            df = self.read_csv(StringIO(data), dialect='mydialect')
        tm.assert_frame_equal(df, exp)
        csv.unregister_dialect('mydialect') 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:dialect.py


示例3: test_dialect_apply

# 需要导入模块: import csv [as 别名]
# 或者: from csv import unregister_dialect [as 别名]
def test_dialect_apply(self):
        class testA(csv.excel):
            delimiter = "\t"
        class testB(csv.excel):
            delimiter = ":"
        class testC(csv.excel):
            delimiter = "|"
        class testUni(csv.excel):
            delimiter = "\u039B"
        csv.register_dialect('testC', testC)
        try:
            self.compare_dialect_123("1,2,3\r\n")
            self.compare_dialect_123("1\t2\t3\r\n", testA)
            self.compare_dialect_123("1:2:3\r\n", dialect=testB())
            self.compare_dialect_123("1|2|3\r\n", dialect='testC')
            self.compare_dialect_123("1;2;3\r\n", dialect=testA,
                                     delimiter=';')
            self.compare_dialect_123("1\u039B2\u039B3\r\n",
                                     dialect=testUni)
        finally:
            csv.unregister_dialect('testC') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_csv.py


示例4: with_csv_dialect

# 需要导入模块: import csv [as 别名]
# 或者: from csv import unregister_dialect [as 别名]
def with_csv_dialect(name, **kwargs):
    """
    Context manager to temporarily register a CSV dialect for parsing CSV.
    Parameters
    ----------
    name : str
        The name of the dialect.
    kwargs : mapping
        The parameters for the dialect.
    Raises
    ------
    ValueError : the name of the dialect conflicts with a builtin one.
    See Also
    --------
    csv : Python's CSV library.
    """
    import csv
    _BUILTIN_DIALECTS = {"excel", "excel-tab", "unix"}
    if name in _BUILTIN_DIALECTS:
        raise ValueError("Cannot override builtin dialect.")
    csv.register_dialect(name, **kwargs)
    yield
    csv.unregister_dialect(name) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:30,代码来源:testing.py


示例5: test_registry

# 需要导入模块: import csv [as 别名]
# 或者: from csv import unregister_dialect [as 别名]
def test_registry(self):
        class myexceltsv(csv.excel):
            delimiter = "\t"
        name = "myexceltsv"
        expected_dialects = csv.list_dialects() + [name]
        expected_dialects.sort()
        csv.register_dialect(name, myexceltsv)
        self.addCleanup(csv.unregister_dialect, name)
        self.assertEqual(csv.get_dialect(name).delimiter, '\t')
        got_dialects = sorted(csv.list_dialects())
        self.assertEqual(expected_dialects, got_dialects) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_csv.py


示例6: test_register_kwargs

# 需要导入模块: import csv [as 别名]
# 或者: from csv import unregister_dialect [as 别名]
def test_register_kwargs(self):
        name = 'fedcba'
        csv.register_dialect(name, delimiter=';')
        self.addCleanup(csv.unregister_dialect, name)
        self.assertEqual(csv.get_dialect(name).delimiter, ';')
        self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_csv.py



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