A generic context manager for readable files.
Project description
Provides the gopen.readable() and gopen.gread() functions.
readable(source) supports with statements for readable file objects:
>>> with gopen.readable(source) as f: >>> <read from f>
gread(source) returns an iterator over input lines:
>>> from gopen import gread >>> lines = gread(source) >>> lines <generator object gread at 0x7f45752ebf10>
<source> can be:
a readable file object,
a file descriptor and
a file pathname.
gzip and bzip2-compressed files will be decompressed on the fly. No side effects: if source is a file descriptor or a file handle, it will not be closed.
Example:
>>> f = open('txt', 'r') >>> for source in ['txt', 'txt.gz', 'txt.bz2', f]: ... print('%r (%r)' % (list(gread(source)), source)) ... ['Simple is\n', 'better than complex.'] ('txt') ['Simple is\n', 'better than complex.'] ('txt.gz') ['Simple is\n', 'better than complex.'] ('txt.bz2') ['Simple is\n', 'better than complex.'] (<_io.TextIOWrapper name='txt' mode='r' encoding='UTF-8'>) >>> f.closed False
Changes
0.6 (2019-05-27)
Python3 only (>= 3.4)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gopen-0.6.6.tar.gz
(4.2 kB
view details)
Built Distribution
gopen-0.6.6-py3-none-any.whl
(4.0 kB
view details)
File details
Details for the file gopen-0.6.6.tar.gz
.
File metadata
- Download URL: gopen-0.6.6.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43ffe039aa5b867ed312362a2a04a501aa7238c6d87f5812c40f399bf6027685 |
|
MD5 | 00365bff251d222c8766245feb5b26c4 |
|
BLAKE2b-256 | cc16417ecaad1cb8b8976e685599ae9347a5491820f1a2128e76d9bd930fb72b |
File details
Details for the file gopen-0.6.6-py3-none-any.whl
.
File metadata
- Download URL: gopen-0.6.6-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a2321842f8bfe5204fe984bc1222c9c789e2a72f171970f2d48d7f04de594c6 |
|
MD5 | 634728d8b847d3295e07069fc4a619d8 |
|
BLAKE2b-256 | 27e042601fe8319dbf0ee0cc3ad1abddb943b184ca70745a56c41a916dff96ec |