本文整理匯總了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