本文整理汇总了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, [])
示例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)
示例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')
示例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)
示例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())
示例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)