用于处理文件的实用程序。
xphyle的Python项目详细描述
xphyle:非常简单的文件处理
xphyle是一个很小的python库,可以轻松地打开压缩的 文件夹。最重要的是,xphyle将使用适当的程序(例如“gzip”)来压缩/解压缩系统中可用的文件;这几乎总是比使用相应的python库快。xphyle还提供了简化常见文件i/o操作的方法。
最新版本的xphyle(4.0.0+)需要python 3.6。旧版本的xphyle支持python 3.4+。
安装
pip install xphyle
从源构建
克隆此存储库并运行
make
示例用法:
fromxphyleimport*fromxphyle.pathsimportSTDIN,STDOUT# Open a compressed file...myfile=xopen('infile.gz')# ...or a compressed stream# e.g. gzip -c afile | python my_program.pystdin=xopen(STDIN)# Easily write to the stdin of a subprocesswithopen_('|cat','wt')asprocess:process.write('foo')# We have to tell xopen what kind of compression# to use when writing to stdoutstdout=xopen(STDOUT,compression='gz')# The `open_` method ensures that the file is usable with the `with` keyword.# Print all lines in a compressed file...withopen_('infile.gz')asmyfile:forlineinmyfile:print(line)# ... or a compressed URLwithopen_('http://foo.com/myfile.gz')asmyfile:forlineinmyfile:print(line)# Transparently handle paths and file objectsdefdostuff(path_or_file):withopen_(path_or_file)asmyfile:forlineinmyfile:print(line)# Read all lines in a compressed file into a listfromxphyle.utilsimportread_lineslines=list(read_lines('infile.gz'))# Sum the rows in a compressed file where each line is an integer valuetotal=sum(read_lines('infile.gz',convert=int))
有关完整用法信息,请参见Documentation。
问题
请使用issue tracker报告错误并请求增强功能。
路线图
未来的版本是使用GitHub Projects绘制的。