當前位置: 首頁>>代碼示例>>Python>>正文


Python csv.list_dialects方法代碼示例

本文整理匯總了Python中csv.list_dialects方法的典型用法代碼示例。如果您正苦於以下問題:Python csv.list_dialects方法的具體用法?Python csv.list_dialects怎麽用?Python csv.list_dialects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在csv的用法示例。


在下文中一共展示了csv.list_dialects方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_registry_badargs

# 需要導入模塊: import csv [as 別名]
# 或者: from csv import list_dialects [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_bad_dialect

# 需要導入模塊: import csv [as 別名]
# 或者: from csv import list_dialects [as 別名]
def test_bad_dialect(self):
        # Unknown parameter
        self.assertRaises(TypeError, csv.reader, [], bad_attr = 0)
        # Bad values
        self.assertRaises(TypeError, csv.reader, [], delimiter = None)
        self.assertRaises(TypeError, csv.reader, [], quoting = -1)
        self.assertRaises(TypeError, csv.reader, [], quoting = 100)

    # See issue #22995
    ## def test_copy(self):
    ##     for name in csv.list_dialects():
    ##         dialect = csv.get_dialect(name)
    ##         self.assertRaises(TypeError, copy.copy, dialect)

    ## def test_pickle(self):
    ##     for name in csv.list_dialects():
    ##         dialect = csv.get_dialect(name)
    ##         for proto in range(pickle.HIGHEST_PROTOCOL + 1):
    ##             self.assertRaises(TypeError, pickle.dumps, dialect, proto) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_csv.py

示例3: main

# 需要導入模塊: import csv [as 別名]
# 或者: from csv import list_dialects [as 別名]
def main():
    print('Starting CSV Exmaple')
    print(csv.list_dialects())

    print('Crearting CSV file')
    with open('sample.csv', 'w', newline='') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(['She Loves You', 'Sept 1963'])
        writer.writerow(['I Want to Hold Your Hand', 'Dec 1963'])
        writer.writerow(['Cant Buy Me Love', 'Apr 1964'])
        writer.writerow(['A Hard Days Night', 'July 1964'])

    print('-' * 100)

    print('Starting to read csv file')
    with open('sample.csv', newline='') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            print(*row, sep=', ')
    print('Done Reading') 
開發者ID:johnehunt,項目名稱:advancedpython3,代碼行數:22,代碼來源:csvexample.py

示例4: test_registry

# 需要導入模塊: import csv [as 別名]
# 或者: from csv import list_dialects [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

示例5: _handle_dialect_option

# 需要導入模塊: import csv [as 別名]
# 或者: from csv import list_dialects [as 別名]
def _handle_dialect_option(argument):
    return rst.directives.choice(argument, ["auto"] + csv.list_dialects()) 
開發者ID:sphinx-contrib,項目名稱:datatemplates,代碼行數:4,代碼來源:directive.py

示例6: test_registry

# 需要導入模塊: import csv [as 別名]
# 或者: from csv import list_dialects [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)
        try:
            self.failUnless(csv.get_dialect(name).delimiter, '\t')
            got_dialects = csv.list_dialects()
            got_dialects.sort()
            self.assertEqual(expected_dialects, got_dialects)
        finally:
            csv.unregister_dialect(name) 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:16,代碼來源:test_csv.py


注:本文中的csv.list_dialects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。