Python ``with`` as a Function
=============================
Use context managers with a function instead of a statement.
Provides a minimal and portable interface for using context
managers with all the advantages of functions over syntax.
Allows using context managers on Python implementations that
are too old or too incomplete to have the ``with`` statement.
Versioning
----------
This library's version numbers follow the `SemVer 2.0.0
specification <https://semver.org/spec/v2.0.0.html>`_.
Installation
------------
::
pip install with-as-a-function
Usage
-----
Import ``with_``, ``iwith``, or both:
.. code:: python
from with_ import with_, iwith
``with_`` wraps a function in a context manager.
For example,
.. code:: python
data = with_(open('my_file.txt'), lambda my_file: my_file.read())
is similar to:
.. code:: python
with open('my_file.txt') as my_file:
data = my_file.read()
``iwith`` wraps a generator or other iterable in a context manager.
For example,
.. code:: python
lines = iwith(open('my_file.txt'), lambda my_file: my_file)
is similar to:
.. code:: python
def _lines():
with open('my_file.txt') as my_file:
yield from my_file
lines = _lines()
And of course because ``with_`` and ``iwith`` are functions, you
can combine them with ``functools.partial`` and other functional
programming libraries and techniques for many more uses.
Portability
-----------
Portable to all releases of Python 3, and releases
of Python 2 starting with 2.2.
*Even those without the* ``with`` *statement and
without the* ``yield from`` *expression.*
For popular Python reimplementations with quicks or bugs that
make the normal implementation of this module not work, other
implementations are included in the source distribution.
Raw data
{
"_id": null,
"home_page": "https://github.com/mentalisttraceur/python-with",
"name": "with-as-a-function",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Alexander Kozhevnikov",
"author_email": "mentalisttraceur@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/13/b8/f93db6505df9b1965496be20b6b0cba88e130978392127e09355444e2553/with-as-a-function-1.1.0.tar.gz",
"platform": null,
"description": "Python ``with`` as a Function\n=============================\n\nUse context managers with a function instead of a statement.\n\nProvides a minimal and portable interface for using context\nmanagers with all the advantages of functions over syntax.\n\nAllows using context managers on Python implementations that\nare too old or too incomplete to have the ``with`` statement.\n\n\nVersioning\n----------\n\nThis library's version numbers follow the `SemVer 2.0.0\nspecification <https://semver.org/spec/v2.0.0.html>`_.\n\n\nInstallation\n------------\n\n::\n\n pip install with-as-a-function\n\n\nUsage\n-----\n\nImport ``with_``, ``iwith``, or both:\n\n.. code:: python\n\n from with_ import with_, iwith\n\n``with_`` wraps a function in a context manager.\nFor example,\n\n.. code:: python\n\n data = with_(open('my_file.txt'), lambda my_file: my_file.read())\n\nis similar to:\n\n.. code:: python\n\n with open('my_file.txt') as my_file:\n data = my_file.read()\n\n``iwith`` wraps a generator or other iterable in a context manager.\nFor example,\n\n.. code:: python\n\n lines = iwith(open('my_file.txt'), lambda my_file: my_file)\n\nis similar to:\n\n.. code:: python\n\n def _lines():\n with open('my_file.txt') as my_file:\n yield from my_file\n lines = _lines()\n\nAnd of course because ``with_`` and ``iwith`` are functions, you\ncan combine them with ``functools.partial`` and other functional\nprogramming libraries and techniques for many more uses.\n\n\nPortability\n-----------\n\nPortable to all releases of Python 3, and releases\nof Python 2 starting with 2.2.\n\n*Even those without the* ``with`` *statement and\nwithout the* ``yield from`` *expression.*\n\nFor popular Python reimplementations with quicks or bugs that\nmake the normal implementation of this module not work, other\nimplementations are included in the source distribution.\n\n\n",
"bugtrack_url": null,
"license": "0BSD",
"summary": "Use context managers with a function instead of a statement.",
"version": "1.1.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "daffe9b9465c4b1f2457ec3fde5d58b6",
"sha256": "f0bd2c03ba0f3cd8c4e0b50e22a46b1a43f4a50eb677bee858fa892bcd78dad6"
},
"downloads": -1,
"filename": "with_as_a_function-1.1.0-py22-none-any.whl",
"has_sig": false,
"md5_digest": "daffe9b9465c4b1f2457ec3fde5d58b6",
"packagetype": "bdist_wheel",
"python_version": "py22",
"requires_python": null,
"size": 4345,
"upload_time": "2022-12-10T07:36:02",
"upload_time_iso_8601": "2022-12-10T07:36:02.312774Z",
"url": "https://files.pythonhosted.org/packages/e6/0e/f7b61d4b19c1f46a9b2c960d6578402287c6509cbad6c39a67109a4616f6/with_as_a_function-1.1.0-py22-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "4a0973edd14d46cc2c945c062a8647a0",
"sha256": "f40c6e3d9457c028f7a9c8a21bc5df7ba6fe46fb68ad19a3592031517b63be4a"
},
"downloads": -1,
"filename": "with_as_a_function-1.1.0-py25-none-any.whl",
"has_sig": false,
"md5_digest": "4a0973edd14d46cc2c945c062a8647a0",
"packagetype": "bdist_wheel",
"python_version": "py25",
"requires_python": null,
"size": 3923,
"upload_time": "2022-12-10T07:36:04",
"upload_time_iso_8601": "2022-12-10T07:36:04.615383Z",
"url": "https://files.pythonhosted.org/packages/42/4f/1cdc260f6431ee2d2f0a9cd04457d8e8a3ea0b56dfc3929a3f18c2339ec4/with_as_a_function-1.1.0-py25-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "817098af24cbe610b33d8e949faad14e",
"sha256": "8c3933e1882002e10e0d53812eaf5d757ccbc2ee478b89c0c456ab8ac17f40b7"
},
"downloads": -1,
"filename": "with_as_a_function-1.1.0-py26.py30-none-any.whl",
"has_sig": false,
"md5_digest": "817098af24cbe610b33d8e949faad14e",
"packagetype": "bdist_wheel",
"python_version": "py26.py30",
"requires_python": null,
"size": 3835,
"upload_time": "2022-12-10T07:36:06",
"upload_time_iso_8601": "2022-12-10T07:36:06.791285Z",
"url": "https://files.pythonhosted.org/packages/3c/47/4a69b0dacd1439f71b7629860433b008a2bef024276dfc873e9487a057d5/with_as_a_function-1.1.0-py26.py30-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "66949c2f5121ab6b0cb01fcc384deff6",
"sha256": "81d2fcd4a6e4daa2fc6837774720170c2d7d607ea51d9a321ca014f3c68d70a5"
},
"downloads": -1,
"filename": "with_as_a_function-1.1.0-py33-none-any.whl",
"has_sig": false,
"md5_digest": "66949c2f5121ab6b0cb01fcc384deff6",
"packagetype": "bdist_wheel",
"python_version": "py33",
"requires_python": null,
"size": 3480,
"upload_time": "2022-12-10T07:36:08",
"upload_time_iso_8601": "2022-12-10T07:36:08.729001Z",
"url": "https://files.pythonhosted.org/packages/56/40/854ec4b4fab059635656ee4370bce2ca5d70c796eb1cfc0cd6c054b64564/with_as_a_function-1.1.0-py33-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "3c9be07b44054b270e3639002eb71cd4",
"sha256": "933da4367185a5265ca5e5a7f34b96c9a4f3a408a3cf5d4c92229ea395bb5165"
},
"downloads": -1,
"filename": "with-as-a-function-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "3c9be07b44054b270e3639002eb71cd4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8137,
"upload_time": "2022-12-10T07:36:10",
"upload_time_iso_8601": "2022-12-10T07:36:10.166962Z",
"url": "https://files.pythonhosted.org/packages/13/b8/f93db6505df9b1965496be20b6b0cba88e130978392127e09355444e2553/with-as-a-function-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-10 07:36:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "mentalisttraceur",
"github_project": "python-with",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "with-as-a-function"
}