How to use the unicodecsv.py2.UnicodeReader function in unicodecsv

To help you get started, we’ve selected a few unicodecsv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jdunck / python-unicodecsv / unicodecsv / py2.py View on Github external
def __init__(self, csvfile, fieldnames=None, restkey=None, restval=None,
                 dialect='excel', encoding='utf-8', errors='strict', *args,
                 **kwds):
        if fieldnames is not None:
            fieldnames = _stringify_list(fieldnames, encoding)
        csv.DictReader.__init__(self, csvfile, fieldnames, restkey, restval,
                                dialect, *args, **kwds)
        self.reader = UnicodeReader(csvfile, dialect, encoding=encoding,
                                    errors=errors, *args, **kwds)
        if fieldnames is None and not hasattr(csv.DictReader, 'fieldnames'):
            # Python 2.5 fieldnames workaround.
            # See http://bugs.python.org/issue3436
            reader = UnicodeReader(csvfile, dialect, encoding=encoding,
                                   *args, **kwds)
            self.fieldnames = _stringify_list(reader.next(), reader.encoding)

        if self.fieldnames is not None:
            self.unicode_fieldnames = [_unicodify(f, encoding) for f in
                                       self.fieldnames]
        else:
            self.unicode_fieldnames = []

        self.unicode_restkey = _unicodify(restkey, encoding)
github jdunck / python-unicodecsv / unicodecsv / py2.py View on Github external
def __init__(self, csvfile, fieldnames=None, restkey=None, restval=None,
                 dialect='excel', encoding='utf-8', errors='strict', *args,
                 **kwds):
        if fieldnames is not None:
            fieldnames = _stringify_list(fieldnames, encoding)
        csv.DictReader.__init__(self, csvfile, fieldnames, restkey, restval,
                                dialect, *args, **kwds)
        self.reader = UnicodeReader(csvfile, dialect, encoding=encoding,
                                    errors=errors, *args, **kwds)
        if fieldnames is None and not hasattr(csv.DictReader, 'fieldnames'):
            # Python 2.5 fieldnames workaround.
            # See http://bugs.python.org/issue3436
            reader = UnicodeReader(csvfile, dialect, encoding=encoding,
                                   *args, **kwds)
            self.fieldnames = _stringify_list(reader.next(), reader.encoding)

        if self.fieldnames is not None:
            self.unicode_fieldnames = [_unicodify(f, encoding) for f in
                                       self.fieldnames]
        else:
            self.unicode_fieldnames = []

        self.unicode_restkey = _unicodify(restkey, encoding)