将Gio.File作为Python文件对象打开
项目描述
将Gio.File作为Python文件对象打开
def open(file, mode="r", buffering=-1, encoding=None, errors=None,
newline=None, cancellable=None):
"""
Like io.open() but takes a Gio.File instead of a filename.
The only modes supported are r/rw/rb/r+b
Takes a cancellable kwarg for passing a Gio.Cancellable().
Cancelling it will abort any ongoing blocking operation.
Returns a io.IOBase instance.
"""
安装
pip install giofile
示例
import mutagen
import giofile
from gi.repository import Gio
gio_file = Gio.File.new_for_uri(
"http://people.xiph.org/~giles/2012/opus/ehren-paper_lights-96.opus")
cancellable = Gio.Cancellable.new()
with giofile.open(gio_file, "rb", cancellable=cancellable) as gfile:
print(mutagen.File(gfile).pprint())
$ python example.py
Ogg Opus, 228.11 seconds (audio/ogg)
ENCODER=opusenc from opus-tools 0.1.5
artist=Ehren Starks
title=Paper Lights
album=Lines Build Walls
date=2005-09-05
copyright=Copyright 2005 Ehren Starks
license=http://creativecommons.org/licenses/by-nc-sa/1.0/
organization=magnatune.com
项目详情
关闭
giofile-0.2.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2e00d57cb3f81a1fd97bca7b6f1696cdc6ec5a409276aea7c27283c4e3e34b77 |
|
MD5 | 72a05637ff76842ea9f86e0e777d246c |
|
BLAKE2b-256 | 88d034dbabf17c9d697578db890acddb7cdf0e76a2591e96462efb179171a3c4 |