csv.py 文件源码

python
阅读 39 收藏 0 点赞 0 评论 0

项目:rowgenerators 作者: Metatab 项目源码 文件源码
def __iter__(self):
        """Iterate over all of the lines in the file"""

        import csv

        try:
            # For: _csv.Error: field larger than field limit (131072)
            if os.name == 'nt':
                # Using sys.maxsize throws an Overflow error on Windows 64-bit platforms since internal
                # representation of 'int'/'long' on Win64 is only 32-bit wide. Ideally limit on Win64
                # should not exceed ((2**31)-1) as long as internal representation uses 'int' and/or 'long'
                csv.field_size_limit((2**31)-1)
            else:
                csv.field_size_limit(sys.maxsize) 
        except OverflowError as e:
            # skip setting the limit for now
            pass

        self.start()

        try:

            # Python 3.6 considers None to mean 'utf8', but Python 3.5 considers it to be 'ascii'
            encoding = self.url.encoding or 'utf8'

            with open(self.url.path, encoding=encoding) as f:
                yield from csv.reader(f, delimiter=self.delimiter)
        except UnicodeError as e:
            raise

        self.finish()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号