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


Python csv.py方法代码示例

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


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

示例1: parse_csv_data_into_rows

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def parse_csv_data_into_rows(self, csv_data, dialect, source):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8
        csv_reader = csv.reader([self.encode_for_csv(line + '\n')
                                 for line in csv_data],
                                dialect=dialect)
        rows = []
        max_cols = 0
        for row in csv_reader:
            row_data = []
            for cell in row:
                # decode UTF-8 back to Unicode
                cell_text = self.decode_from_csv(cell)
                cell_data = (0, 0, 0, statemachine.StringList(
                    cell_text.splitlines(), source=source))
                row_data.append(cell_data)
            rows.append(row_data)
            max_cols = max(max_cols, len(row))
        return rows, max_cols 
开发者ID:skarlekar,项目名称:faces,代码行数:20,代码来源:tables.py

示例2: read_csv

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def read_csv(handle):
    """ Read CSV file
    :param handle: File-like object of the CSV file
    :return: csv.reader object
    """

    # These functions are to handle unicode in Python 2 as described in:
    # https://docs.python.org/2/library/csv.html#examples
    def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
        """ csv.py doesn't do Unicode; encode temporarily as UTF-8."""
        csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                                dialect=dialect, **kwargs)
        for row in csv_reader:
            # decode UTF-8 back to Unicode, cell by cell:
            yield [unicode(cell, 'utf-8') for cell in row]

    def utf_8_encoder(unicode_csv_data):
        """ Encode with UTF-8."""
        for line in unicode_csv_data:
            yield line.encode('utf-8')

    return unicode_csv_reader(handle) if PY2 else csv.reader(handle) 
开发者ID:bloomberg,项目名称:pycsvw,代码行数:24,代码来源:generator_utils.py

示例3: unicode_csv_reader

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
    # csv.py doesn't do Unicode; encode temporarily as UTF-8:
    csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
            dialect=dialect, **kwargs)
    for row in csv_reader:
        # decode UTF-8 back to Unicode, cell by cell:
        yield [unicode(cell, 'utf-8') for cell in row] 
开发者ID:verejnedigital,项目名称:verejne.digital,代码行数:9,代码来源:main.py

示例4: unicode_csv_reader

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
    # csv.py doesn't do Unicode; encode temporarily as UTF-8:
    csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                            dialect=dialect, **kwargs)
    for row in csv_reader:
        # decode UTF-8 back to Unicode, cell by cell:
        yield [unicode(cell, 'utf-8') for cell in row] 
开发者ID:ChristopherLucas,项目名称:txtorg,代码行数:9,代码来源:addmetadata.py

示例5: unicode_csv_reader

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
    # csv.py doesn't do Unicode; encode temporarily as UTF-8:
    csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                            dialect=dialect, **kwargs)
    for row in csv_reader:
        # decode UTF-8 back to Unicode, cell by cell:
        yield [cell.decode('utf-8') for cell in row] 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:9,代码来源:bf_elections_2015_import_candidate.py

示例6: _unicode_csv_reader

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def _unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
    # csv.py doesn't do Unicode; encode temporarily as UTF-8:
    csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                            dialect=dialect, **kwargs)
    for row in csv_reader:
        # decode UTF-8 back to Unicode, cell by cell:
        yield [unicode(cell, 'utf-8') for cell in row] 
开发者ID:ibmresilient,项目名称:resilient-community-apps,代码行数:9,代码来源:utils.py

示例7: unicode_csv_reader

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
    # csv.py doesn't do Unicode; encode temporarily as UTF-8:
    csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                            dialect=dialect, **kwargs)
    for row in csv_reader:
        # decode UTF-8 back to Unicode, cell by cell:
        # TODO: Is this py3 compatible?
        yield [unicode(cell, 'utf-8') for cell in row]  # noqa: F821; protected by PY3 check 
开发者ID:mitre,项目名称:multiscanner,代码行数:10,代码来源:nsrl_parse.py

示例8: worksheet_from_csv

# 需要导入模块: import csv [as 别名]
# 或者: from csv import py [as 别名]
def worksheet_from_csv(
    worksheet, csv_file, start_column, start_row, excel_encoding
):

    def autodetect_encoding(csv_file):
        detector = UniversalDetector()
        for line in csv_file.readlines():
            detector.feed(line)
            if detector.done: break
        detector.close()
        csv_file.seek(0)
        encoding = detector.result['encoding']

        if not encoding:
            raise DirigibleImportError('could not recognise encoding')

        return encoding

    def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
        # csv.py doesn't do Unicode; encode temporarily as UTF-8:
        csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                                dialect=dialect, **kwargs)
        for row in csv_reader:
            # decode UTF-8 back to Unicode, cell by cell:
            yield [unicode(cell, 'utf-8') for cell in row]

    def utf_8_encoder(unicode_csv_data):
        for line in unicode_csv_data:
            yield line.encode('utf-8')


    if excel_encoding:
        encoding = 'windows-1252'
    else:
        encoding = autodetect_encoding(csv_file)
    unicode_translated_csv_file = getreader(encoding)(csv_file)

    row = start_row
    try:
        for csv_row in unicode_csv_reader(unicode_translated_csv_file):
            column = start_column
            for csv_cell in csv_row:
                worksheet[column, row].formula = unicode(csv_cell)
                column += 1
            row += 1
    except Exception, e:
        raise DirigibleImportError(unicode(e)) 
开发者ID:pythonanywhere,项目名称:dirigible-spreadsheet,代码行数:49,代码来源:importer.py


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