Skip to main content

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.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

gopen-0.6.4-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file gopen-0.6.4.tar.gz.

File metadata

  • Download URL: gopen-0.6.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for gopen-0.6.4.tar.gz
Algorithm Hash digest
SHA256 d0f36fc23dcd98e02ab8cb74ecba917df304d86dfda6d66e7ceeea425dc8a470
MD5 e33a19d705af1ff8706d7de3914049ff
BLAKE2b-256 5d8d5e1b41c77ee35ce41a0cc8e7612d333705382bc98dbec7de918fadfc50b3

See more details on using hashes here.

File details

Details for the file gopen-0.6.4-py3-none-any.whl.

File metadata

  • Download URL: gopen-0.6.4-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

File hashes

Hashes for gopen-0.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f555d016c9ea5f72f32938880115fe5f0960d00ab94f6544f64e5790b9b10b2f
MD5 203da844533866469cc1767449e99ec1
BLAKE2b-256 cf9311568e1e0868e03d2777a42351e1a1e1e0e65b163e1629c169d88fcdd69e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page