main.py 文件源码

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

项目:WikiClassify2.0 作者: bfaure 项目源码 文件源码
def expand_bz2(file_path):
    sys.stdout.write("\tExpanding bz2... ")
    if not os.path.isfile(file_path[:-4]):
        file_size = os.path.getsize(file_path)
        estimated_file_size = (float(5)*float(file_size))/1000.0
        sys.stdout.write("Estimated "+str(estimated_file_size)+" MB\n")
        try:
            with open(file_path[:-4], 'wb') as new_file, bz2.BZ2File(file_path, 'rb') as file:
                for data in iter(lambda : file.read(100 * 1024), b''):
                    new_file.write(data)

                    num_items = int( float(file.tell())/float(file_size)*float(5) )
                    progress_string = ""
                    for prog_index in range(25):
                        if prog_index <= num_items: progress_string+="-"
                        else: progress_string += " "
                    sys.stdout.write("\r\t\t["+progress_string+"] "+str(100.0*file.tell()/file_size)[:5]+"% done")
                    sys.stdout.flush()
                sys.stdout.write("\n")
        except:
            print("\t\tCould not expand file.")
    else:
        print("\t\tFile already expanded.")
    return file_path[:-4]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号