Utils.py 文件源码

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

项目:spartacus 作者: wind39 项目源码 文件源码
def Open(self):
        try:
            if not os.path.isfile(self.v_filename):
                raise Spartacus.Utils.Exception('File {0} does not exist or is not a file.'.format(self.v_filename))
            if self.v_extension == 'csv':
                self.v_file = open(self.v_filename, encoding=self.v_encoding)
                v_sample = self.v_file.read(1024)
                self.v_file.seek(0)
                v_sniffer = csv.Sniffer()
                if not v_sniffer.has_header(v_sample):
                    raise Spartacus.Utils.Exception('CSV file {0} does not have a header.'.format(self.v_filename))
                v_dialect = v_sniffer.sniff(v_sample)
                self.v_object = csv.DictReader(self.v_file, self.v_header, None, None, v_dialect)
                self.v_open = True
            elif self.v_extension == 'xlsx':
                self.v_object = openpyxl.load_workbook(self.v_filename, read_only=True)
                self.v_open = True
            else:
                raise Spartacus.Utils.Exception('File extension "{0}" not supported.'.format(self.v_extension))
        except Spartacus.Utils.Exception as exc:
            raise exc
        except Exception as exc:
            raise Spartacus.Utils.Exception(str(exc))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号