本文整理匯總了Python中unicodecsv.QUOTE_MINIMAL屬性的典型用法代碼示例。如果您正苦於以下問題:Python unicodecsv.QUOTE_MINIMAL屬性的具體用法?Python unicodecsv.QUOTE_MINIMAL怎麽用?Python unicodecsv.QUOTE_MINIMAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類unicodecsv
的用法示例。
在下文中一共展示了unicodecsv.QUOTE_MINIMAL屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _test_default_attrs
# 需要導入模塊: import unicodecsv [as 別名]
# 或者: from unicodecsv import QUOTE_MINIMAL [as 別名]
def _test_default_attrs(self, ctor, *args):
obj = ctor(*args)
# Check defaults
self.assertEqual(obj.dialect.delimiter, ',')
self.assertEqual(obj.dialect.doublequote, True)
self.assertEqual(obj.dialect.escapechar, None)
self.assertEqual(obj.dialect.lineterminator, "\r\n")
self.assertEqual(obj.dialect.quotechar, '"')
self.assertEqual(obj.dialect.quoting, csv.QUOTE_MINIMAL)
self.assertEqual(obj.dialect.skipinitialspace, False)
self.assertEqual(obj.dialect.strict, False)
# Try deleting or changing attributes (they are read-only)
self.assertRaises(py_compat_exc, delattr,
obj.dialect, 'delimiter')
self.assertRaises(py_compat_exc, setattr,
obj.dialect, 'delimiter', ':')
self.assertRaises(py_compat_exc, delattr,
obj.dialect, 'quoting')
self.assertRaises(py_compat_exc, setattr,
obj.dialect, 'quoting', None)
示例2: test_write_escape
# 需要導入模塊: import unicodecsv [as 別名]
# 或者: from unicodecsv import QUOTE_MINIMAL [as 別名]
def test_write_escape(self):
self._write_test(['a', 1, 'p,q'], b'a,1,"p,q"',
escapechar='\\')
self.assertRaises(csv.Error,
self._write_test,
['a', 1, 'p,"q"'], b'a,1,"p,\\"q\\""',
escapechar=None, doublequote=False)
self._write_test(['a', 1, 'p,"q"'], b'a,1,"p,\\"q\\""',
escapechar='\\', doublequote=False)
self._write_test(['"'], b'""""',
escapechar='\\', quoting=csv.QUOTE_MINIMAL)
self._write_test(['"'], b'\\"',
escapechar='\\', quoting=csv.QUOTE_MINIMAL,
doublequote=False)
self._write_test(['"'], b'\\"',
escapechar='\\', quoting=csv.QUOTE_NONE)
self._write_test(['a', 1, 'p,q'], b'a,1,p\\,q',
escapechar='\\', quoting=csv.QUOTE_NONE)
示例3: __init__
# 需要導入模塊: import unicodecsv [as 別名]
# 或者: from unicodecsv import QUOTE_MINIMAL [as 別名]
def __init__(
self,
filename,
azure_data_lake_conn_id,
azure_data_lake_path,
oracle_conn_id,
sql,
sql_params=None,
delimiter=",",
encoding="utf-8",
quotechar='"',
quoting=csv.QUOTE_MINIMAL,
*args, **kwargs):
super().__init__(*args, **kwargs)
if sql_params is None:
sql_params = {}
self.filename = filename
self.oracle_conn_id = oracle_conn_id
self.sql = sql
self.sql_params = sql_params
self.azure_data_lake_conn_id = azure_data_lake_conn_id
self.azure_data_lake_path = azure_data_lake_path
self.delimiter = delimiter
self.encoding = encoding
self.quotechar = quotechar
self.quoting = quoting
示例4: __init__
# 需要導入模塊: import unicodecsv [as 別名]
# 或者: from unicodecsv import QUOTE_MINIMAL [as 別名]
def __init__( # pylint: disable=too-many-arguments
self,
sql: str,
hive_table: str,
create: bool = True,
recreate: bool = False,
partition: Optional[Dict] = None,
delimiter: str = chr(1),
quoting: Optional[str] = None,
quotechar: str = '"',
escapechar: Optional[str] = None,
mysql_conn_id: str = 'mysql_default',
hive_cli_conn_id: str = 'hive_cli_default',
tblproperties: Optional[Dict] = None,
*args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.sql = sql
self.hive_table = hive_table
self.partition = partition
self.create = create
self.recreate = recreate
self.delimiter = str(delimiter)
self.quoting = quoting or csv.QUOTE_MINIMAL
self.quotechar = quotechar
self.escapechar = escapechar
self.mysql_conn_id = mysql_conn_id
self.hive_cli_conn_id = hive_cli_conn_id
self.partition = partition or {}
self.tblproperties = tblproperties
示例5: convert_file_to_csv_string
# 需要導入模塊: import unicodecsv [as 別名]
# 或者: from unicodecsv import QUOTE_MINIMAL [as 別名]
def convert_file_to_csv_string(path):
"""
This will open a csv or xls file and return a CSV in the format:
sheet_name1
,col1,col2
,r1c1,r1c2
,r2c1,r2c2
sheet_name2
,col1,col2
,r1c1,r1c2
,r2c1,r2c2
Currently, it processes csv files and xls files to ensure consistent
csv delimiters, etc. for tests.
"""
if path.endswith(".csv"):
imported_sheets = csv_to_dict(path)
else:
imported_sheets = xls_to_dict(path)
foo = BytesIO()
writer = csv.writer(foo, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
for sheet_name, rows in imported_sheets.items():
writer.writerow([sheet_name])
out_keys = []
out_rows = []
for row in rows:
out_row = []
for key in row.keys():
if key not in out_keys:
out_keys.append(key)
for out_key in out_keys:
out_row.append(row.get(out_key, None))
out_rows.append(out_row)
writer.writerow([None] + out_keys)
for out_row in out_rows:
writer.writerow([None] + out_row)
return foo.getvalue().decode("utf-8")
示例6: test_write_quoting
# 需要導入模塊: import unicodecsv [as 別名]
# 或者: from unicodecsv import QUOTE_MINIMAL [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)
示例7: to_csv
# 需要導入模塊: import unicodecsv [as 別名]
# 或者: from unicodecsv import QUOTE_MINIMAL [as 別名]
def to_csv(self, query, path, log_progress=True, **kwargs):
"""
Write query results to CSV. Optional keyword arguments are
provided to the csv writer object, allowing control over
delimiters, quoting, etc. The default is comma-separated
with csv.QUOTE_MINIMAL
::
d2 = DirectAccessV2(client_id, client_secret, api_key)
query = d2.query('rigs', deleteddate='null', pagesize=1500)
# Write tab-separated file
d2.to_csv(query, '/path/to/rigs.csv', delimiter='\\t')
:param query: DirectAccessV1 or DirectAccessV2 query object
:param path: relative or absolute filesystem path for created CSV
:type path: str
:param log_progress: whether to log progress. if True, log a message with current written count
:type log_progress: bool
:return: the newly created CSV file path
"""
with open(path, mode="wb") as f:
writer = csv.writer(f, **kwargs)
count = None
for i, row in enumerate(query, start=1):
row = OrderedDict(sorted(row.items(), key=lambda t: t[0]))
count = i
if count == 1:
writer.writerow(row.keys())
writer.writerow(row.values())
if log_progress and i % 100000 == 0:
self.logger.info(
"Wrote {count} records to file {path}".format(
count=count, path=path
)
)
self.logger.info(
"Completed writing CSV file to {path}. Final count {count}".format(
path=path, count=count
)
)
return path