Python unicodecsv.QUOTE_NONNUMERIC Examples
The following are 5
code examples of unicodecsv.QUOTE_NONNUMERIC().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
unicodecsv
, or try the search function
.
Example #1
Source File: csv_adapter.py From salesforce-bulk with MIT License | 6 votes |
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()
Example #2
Source File: test.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: test.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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)
Example #4
Source File: test.py From pyRevit with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: file_system_neo4j_csv_loader.py From amundsendatabuilder with Apache License 2.0 | 4 votes |
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