当前位置: 首页>>代码示例>>Python>>正文


Python unicodecsv.QUOTE_MINIMAL属性代码示例

本文整理汇总了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) 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:22,代码来源:test.py

示例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) 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:20,代码来源:test.py

示例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 
开发者ID:apache,项目名称:airflow,代码行数:28,代码来源:oracle_to_azure_data_lake.py

示例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 
开发者ID:apache,项目名称:airflow,代码行数:31,代码来源:mysql_to_hive.py

示例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") 
开发者ID:XLSForm,项目名称:pyxform,代码行数:39,代码来源:xls2json_backends.py

示例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) 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:16,代码来源:test.py

示例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 
开发者ID:wchatx,项目名称:direct-access-py,代码行数:45,代码来源:__init__.py


注:本文中的unicodecsv.QUOTE_MINIMAL属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。