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


Python csv.get_dialect方法代码示例

本文整理汇总了Python中csv.get_dialect方法的典型用法代码示例。如果您正苦于以下问题:Python csv.get_dialect方法的具体用法?Python csv.get_dialect怎么用?Python csv.get_dialect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在csv的用法示例。


在下文中一共展示了csv.get_dialect方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_build_csv_multiple_cols

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_build_csv_multiple_cols():
    lt = os.linesep
    dm = csv.get_dialect('excel').delimiter
    data = [
        co.OrderedDict([('col1', 'value'),
                        ('col2', 'another value'),
                        ('col3', 'more')]),
        co.OrderedDict([('col1', 'one value'),
                        ('col2', 'two value'),
                        ('col3', 'three')])
    ]
    result = lt.join([
        dm.join(['col1', 'col2', 'col3']),
        dm.join(['value', 'another value', 'more']),
        dm.join(['one value', 'two value', 'three'])
        ]) + lt
    assert build_csv(data) == result


# sorted_groupby 
开发者ID:TailorDev,项目名称:Watson,代码行数:22,代码来源:test_utils.py

示例2: test_registry_badargs

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_registry_badargs(self):
        self.assertRaises(TypeError, csv.list_dialects, None)
        self.assertRaises(TypeError, csv.get_dialect)
        self.assertRaises(csv.Error, csv.get_dialect, None)
        self.assertRaises(csv.Error, csv.get_dialect, "nonesuch")
        self.assertRaises(TypeError, csv.unregister_dialect)
        self.assertRaises(csv.Error, csv.unregister_dialect, None)
        self.assertRaises(csv.Error, csv.unregister_dialect, "nonesuch")
        self.assertRaises(TypeError, csv.register_dialect, None)
        self.assertRaises(TypeError, csv.register_dialect, None, None)
        self.assertRaises(TypeError, csv.register_dialect, "nonesuch", 0, 0)
        self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
                          badargument=None)
        self.assertRaises(TypeError, csv.register_dialect, "nonesuch",
                          quoting=None)
        self.assertRaises(TypeError, csv.register_dialect, []) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_csv.py

示例3: test_bad_dialect

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_bad_dialect(self):
        # Unknown parameter
        self.assertRaises(TypeError, csv.reader, [], bad_attr = 0)
        # Bad values
        self.assertRaises(TypeError, csv.reader, [], delimiter = None)
        self.assertRaises(TypeError, csv.reader, [], quoting = -1)
        self.assertRaises(TypeError, csv.reader, [], quoting = 100)

    # See issue #22995
    ## def test_copy(self):
    ##     for name in csv.list_dialects():
    ##         dialect = csv.get_dialect(name)
    ##         self.assertRaises(TypeError, copy.copy, dialect)

    ## def test_pickle(self):
    ##     for name in csv.list_dialects():
    ##         dialect = csv.get_dialect(name)
    ##         for proto in range(pickle.HIGHEST_PROTOCOL + 1):
    ##             self.assertRaises(TypeError, pickle.dumps, dialect, proto) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_csv.py

示例4: __call__

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def __call__(self, context):
        # get Dialect object
        if isinstance(self._dialect, types.StringTypes):
            dialect = csv.get_dialect(self._dialect)

        # get content
        content = self._content
        if self._content is None:
            if self._path.startswith(HTTP_SCHEMA):
                content = requests.get(self._path).text
            else:
                with open(self._path, "r") as f:
                    content = f.read()

        if isinstance(content, types.StringTypes):
            content = StringIO.StringIO(content)

        result = []
        csv_reader = csv.reader(content, dialect=dialect)
        for row in csv_reader:
            self._handle_record(row, result.append)

        return self._handle_result(context, result) 
开发者ID:chihongze,项目名称:girlfriend,代码行数:25,代码来源:csv.py

示例5: _make_python_dialect

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def _make_python_dialect(self, dialect, **fmtparams):
        if isinstance(dialect, str):
            d = csv.get_dialect(dialect)
        elif isinstance(dialect, csv.Dialect):
            d = dialect
        elif isinstance(dialect, SimpleDialect):
            d = dialect.to_csv_dialect()

        # We have to subclass the csv.Dialect
        props = {k: getattr(d, k) for k in DIALECT_KEYS if hasattr(d, k)}
        for key, value in fmtparams.items():
            props[key] = value
        # lineterminator must be set
        if not "lineterminator" in props or props["lineterminator"] is None:
            props["lineterminator"] = "\n"
        newdialect = type("dialect", (csv.Dialect,), props)
        return newdialect 
开发者ID:alan-turing-institute,项目名称:CleverCSV,代码行数:19,代码来源:write.py

示例6: test_registry

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_registry(self):
        class myexceltsv(csv.excel):
            delimiter = "\t"
        name = "myexceltsv"
        expected_dialects = csv.list_dialects() + [name]
        expected_dialects.sort()
        csv.register_dialect(name, myexceltsv)
        self.addCleanup(csv.unregister_dialect, name)
        self.assertEqual(csv.get_dialect(name).delimiter, '\t')
        got_dialects = sorted(csv.list_dialects())
        self.assertEqual(expected_dialects, got_dialects) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_csv.py

示例7: test_register_kwargs

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_register_kwargs(self):
        name = 'fedcba'
        csv.register_dialect(name, delimiter=';')
        self.addCleanup(csv.unregister_dialect, name)
        self.assertEqual(csv.get_dialect(name).delimiter, ';')
        self.assertEqual([['X', 'Y', 'Z']], list(csv.reader(['X;Y;Z'], name))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_csv.py

示例8: __init__

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def __init__(self, fd, encoding, ui):
        self.fd = fd
        #  dataset_dialect is set by investigate_encoding_and_dialect in utils
        self.dialect = csv.get_dialect('dataset_dialect')
        self.encoding = encoding
        self._ui = ui 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:8,代码来源:reader.py

示例9: go

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def go(self):
        dataset_dialect = csv.get_dialect('dataset_dialect')
        args = ([self.batch_gen_args,
                 SerializableDialect.from_dialect(dataset_dialect),
                 self.queue])
        self.p = multiprocessing.Process(target=self._shove,
                                         args=args,
                                         name='Shovel_Proc')
        self.p.start()
        return self.p 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:12,代码来源:reader.py

示例10: __init__

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def __init__(self, n_samples, out_file, pid, lid, keep_cols,
                 n_retry, delimiter, dataset, pred_name, ui, file_context,
                 fast_mode, encoding, skip_row_id, output_delimiter,
                 pred_threshold_name, pred_decision_name,
                 max_prediction_explanations,
                 ):
        self.n_samples = n_samples
        self.out_file = out_file
        self.project_id = pid
        self.model_id = lid
        self.keep_cols = keep_cols
        self.n_retry = n_retry
        self.delimiter = delimiter
        self.dataset = dataset
        self.pred_name = pred_name
        self.pred_threshold_name = pred_threshold_name
        self.pred_decision_name = pred_decision_name
        self.out_stream = None
        self._ui = ui
        self.file_context = file_context
        self.fast_mode = fast_mode
        self.encoding = encoding
        self.skip_row_id = skip_row_id
        self.output_delimiter = output_delimiter
        #  dataset_dialect and writer_dialect are set by
        #  investigate_encoding_and_dialect in utils
        self.dialect = csv.get_dialect('dataset_dialect')
        self.writer_dialect = csv.get_dialect('writer_dialect')
        self.scoring_succeeded = False  # Removes shelves when True
        self.is_open = False  # Removes shelves when True
        self.max_prediction_explanations = max_prediction_explanations 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:33,代码来源:writer.py

示例11: open

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def open(self):
        if self.is_open:
            self._ui.debug('OPEN CALLED ON ALREADY OPEN RUNCONTEXT')
            return
        self.is_open = True
        self._ui.debug('OPEN CALLED ON RUNCONTEXT')
        csv.register_dialect('dataset_dialect', **self.dialect)
        csv.register_dialect('writer_dialect', **self.writer_dialect)
        self.dialect = csv.get_dialect('dataset_dialect')
        self.writer_dialect = csv.get_dialect('writer_dialect')
        self.db = shelve.open(self.file_context.file_name, writeback=True)
        if six.PY2:
            self.out_stream = open(self.out_file, 'ab')
        elif six.PY3:
            self.out_stream = open(self.out_file, 'a', newline='') 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:17,代码来源:writer.py

示例12: test_investigate_encoding_and_dialect

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_investigate_encoding_and_dialect():
    with UI(None, logging.DEBUG, stdout=False) as ui:
        data = 'tests/fixtures/windows_encoded.csv'
        encoding = investigate_encoding_and_dialect(data, None, ui)
        dialect = csv.get_dialect('dataset_dialect')
        assert encoding == 'windows-1252'
        assert dialect.lineterminator == '\r\n'
        assert dialect.quotechar == '"'
        assert dialect.delimiter == ',' 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:11,代码来源:test_utils.py

示例13: test_investigate_encoding_and_dialect_skip_dialect

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_investigate_encoding_and_dialect_skip_dialect():

    with UI(None, logging.DEBUG, stdout=False) as ui:
        with mock.patch('datarobot_batch_scoring.reader.csv.Sniffer') as sn:
            data = 'tests/fixtures/windows_encoded.csv'
            encoding = investigate_encoding_and_dialect(data, None, ui,
                                                        fast=False,
                                                        encoding='',
                                                        skip_dialect=True)
        assert encoding == 'windows-1252'
        assert not sn.called
        dialect = csv.get_dialect('dataset_dialect')
        assert dialect.delimiter == ',' 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:15,代码来源:test_utils.py

示例14: test_investigate_encoding_and_dialect_substitute_delimiter

# 需要导入模块: import csv [as 别名]
# 或者: from csv import get_dialect [as 别名]
def test_investigate_encoding_and_dialect_substitute_delimiter():

    with UI(None, logging.DEBUG, stdout=False) as ui:
        with mock.patch('datarobot_batch_scoring.reader.csv.Sniffer') as sn:
            data = 'tests/fixtures/windows_encoded.csv'
            encoding = investigate_encoding_and_dialect(data, '|', ui,
                                                        fast=False,
                                                        encoding='',
                                                        skip_dialect=True)
        assert encoding == 'windows-1252'
        assert not sn.called
        dialect = csv.get_dialect('dataset_dialect')
        assert dialect.delimiter == '|' 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:15,代码来源:test_utils.py


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