本文整理汇总了Python中unicodecsv.QUOTE_NONNUMERIC属性的典型用法代码示例。如果您正苦于以下问题:Python unicodecsv.QUOTE_NONNUMERIC属性的具体用法?Python unicodecsv.QUOTE_NONNUMERIC怎么用?Python unicodecsv.QUOTE_NONNUMERIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类unicodecsv
的用法示例。
在下文中一共展示了unicodecsv.QUOTE_NONNUMERIC属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_NONNUMERIC [as 别名]
def next(self):
row = next(self.source)
self.buffer.truncate(0)
self.buffer.seek(0)
if not self.csv:
self.csv = csv.DictWriter(self.buffer, list(row.keys()), quoting=csv.QUOTE_NONNUMERIC)
self.add_header = True
if self.add_header:
if hasattr(self.csv, 'writeheader'):
self.csv.writeheader()
else:
self.csv.writerow(dict((fn, fn) for fn in self.csv.fieldnames))
self.add_header = False
self.csv.writerow(row)
self.buffer.seek(0)
return self.buffer.read()
示例2: test_write_quoting
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_NONNUMERIC [as 别名]
def test_write_quoting(self):
self._write_test(['a', 1, 'p,q'], b'a,1,"p,q"')
self.assertRaises(csv.Error,
self._write_test,
['a', 1, 'p,q'], b'a,1,p,q',
quoting=csv.QUOTE_NONE)
self._write_test(['a', 1, 'p,q'], b'a,1,"p,q"',
quoting=csv.QUOTE_MINIMAL)
self._write_test(['a', 1, 'p,q'], b'"a",1,"p,q"',
quoting=csv.QUOTE_NONNUMERIC)
self._write_test(['a', 1, 'p,q'], b'"a","1","p,q"',
quoting=csv.QUOTE_ALL)
self._write_test(['a\nb', 1], b'"a\nb","1"',
quoting=csv.QUOTE_ALL)
示例3: test_write_decimal
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_NONNUMERIC [as 别名]
def test_write_decimal(self):
self._write_test(['a', decimal.Decimal("1.1"), 'p,q'], b'"a",1.1,"p,q"',
quoting=csv.QUOTE_NONNUMERIC)
示例4: test_read_quoting
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_NONNUMERIC [as 别名]
def test_read_quoting(self):
self._read_test([b'1,",3,",5'], [['1', ',3,', '5']])
self._read_test([b'1,",3,",5'], [['1', '"', '3', '"', '5']],
quotechar=None, escapechar='\\')
self._read_test([b'1,",3,",5'], [['1', '"', '3', '"', '5']],
quoting=csv.QUOTE_NONE, escapechar='\\')
# will this fail where locale uses comma for decimals?
self._read_test([b',3,"5",7.3, 9'], [['', 3, '5', 7.3, 9]],
quoting=csv.QUOTE_NONNUMERIC)
self._read_test([b'"a\nb", 7'], [['a\nb', ' 7']])
self.assertRaises(ValueError, self._read_test,
[b'abc,3'], [[]],
quoting=csv.QUOTE_NONNUMERIC)
示例5: _get_writer
# 需要导入模块: import unicodecsv [as 别名]
# 或者: from unicodecsv import QUOTE_NONNUMERIC [as 别名]
def _get_writer(self,
csv_record_dict, # type: Dict[str, Any]
file_mapping, # type: Dict[Any, DictWriter]
key, # type: Any
dir_path, # type: str
file_suffix # type: str
):
# type: (...) -> DictWriter
"""
Finds a writer based on csv record, key.
If writer does not exist, it's creates a csv writer and update the
mapping.
:param csv_record_dict:
:param file_mapping:
:param key:
:param file_suffix:
:return:
"""
writer = file_mapping.get(key)
if writer:
return writer
LOGGER.info('Creating file for {}'.format(key))
if six.PY2:
file_out = open('{}/{}.csv'.format(dir_path, file_suffix), 'w')
writer = csv.DictWriter(file_out, fieldnames=csv_record_dict.keys(),
quoting=csv.QUOTE_NONNUMERIC, encoding='utf-8')
else:
file_out = open('{}/{}.csv'.format(dir_path, file_suffix), 'w', encoding='utf8')
writer = csv.DictWriter(file_out, fieldnames=csv_record_dict.keys(),
quoting=csv.QUOTE_NONNUMERIC)
def file_out_close():
# type: () -> None
LOGGER.info('Closing file IO {}'.format(file_out))
file_out.close()
self._closer.register(file_out_close)
writer.writeheader()
file_mapping[key] = writer
return writer