__init__.py 文件源码

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

项目:pheweb 作者: statgen 项目源码 文件源码
def import_phenolist(filepath, has_header):
    # Return a list-of-dicts with the original column names, or integers if none.
    # It'd be great to use pandas for this.
    if not os.path.exists(filepath):
        raise PheWebError("ERROR: unable to import {!r} because it doesn't exist".format(filepath))
    # 1. try openpyxl.
    phenos = _import_phenolist_xlsx(filepath, has_header)
    if phenos is not None:
        return phenos
    with read_maybe_gzip(filepath) as f:
        # 2. try json.load(f)
        try:
            return json.load(f)
        except ValueError:
            if filepath.endswith('.json'):
                raise PheWebError("The filepath {!r} ends with '.json' but reading it as json failed.".format(filepath))
        # 3. try csv.reader() with csv.Sniffer().sniff()
        f.seek(0)
        phenos = _import_phenolist_csv(f, has_header)
        if phenos is not None:
            return phenos
        raise PheWebError("I couldn't figure out how to open the file {!r}, sorry.".format(filepath))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号