{ "info": { "author": "Yatharth Agarwal", "author_email": "yatharth999@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5" ], "description": "# attach\n\nYou can install this Python package using `pip install attach`.\n\n\n## How does this work?\n\nHere is an example session:\n\n >>> from attach import Namespace, attach\n >>>\n >>> foo = Namespace()\n >>> with attach(foo):\n ... bar = 'bar'\n ... baz = 'baz'\n ...\n >>>\n >>> bar\n Traceback (most recent call last):\n ...\n NameError: name 'bar' is not defined\n\nNotice that since we defined `bar` inside the `attach(foo)` context, `bar` does not exist as a global.\n Instead, it's value is saved to the namespace `foo`:\n\n >>> foo.bar\n 'bar'\n\nWe can reattach the namespace later:\n\n >>> with attach(foo):\n ... print(bar)\n ...\n bar\n\n## What\u2019s the point?\n\nThe module is especially useful inside Jupyter notebooks. Quite often,\n we have constructions like this:\n\n X = np.array([1, 2, 3])\n def increment(X):\n return X + 1\n\nIn other words, we have globals and function parameters or local variables by the same name.\n However, this can lead to unintended references in the case of a typo,\n or difficulty keeping everything modular.\n\nBy keeping variables out of globals and inside namespaces, you can force functions to only\n use the variables that have been explicitly passed in, thereby preventing many tricky bugs!\n\n\n## Isn\u2019t hacking globals evil?\n\nYes, for good reason, but this is not meant to be used in code files or in production, bur rather in exploratory Jupyter notebooks.\n\n\n## What\u2019s this `Namespace` class?\n\nYou can pass any dictionary-like object into `attach()`; it does not have an instance\n of the `Namespace` class defined in this package.\n\nThe `Namespace` class just has a few niceties, like a nice string representation, and\n allowing you to attributes both as `foo.bar` and `foo['bar']`.\n\n\n## Stuff you should know\n\n- By default, variables beginning with an underscore are not saved to the namespace; they are lost.\n To change this behaviour, set `skip_underscored=False` in `attach()`.\n\n- `attach()` only concerns itself with globals. If you call it inside a function,\n beware unexpected behaviour.\n\n## To Do\n\n- Add a `read_only` paramater to `attach()`, which enables using namespaces in a\n nested way when neeed.\n- Check if being called inside a function, and error out unless `read_only=True`\n since we can\u2019t modify function locals, only globals.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/yatharth/attach", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "attach", "package_url": "https://pypi.org/project/attach/", "platform": "", "project_url": "https://pypi.org/project/attach/", "project_urls": { "Homepage": "https://github.com/yatharth/attach" }, "release_url": "https://pypi.org/project/attach/0.1/", "requires_dist": null, "requires_python": "", "summary": "Attaching and detaching namespaces to keep globals clean", "version": "0.1" }, "last_serial": 4159172, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "650102d8c5502674e28cfcfdf60bbba7", "sha256": "355d801bc94c778abf45e26eee11e79791db887461fd008b5dbe8ced92b98d60" }, "downloads": -1, "filename": "attach-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "650102d8c5502674e28cfcfdf60bbba7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4118, "upload_time": "2018-08-11T06:51:06", "url": "https://files.pythonhosted.org/packages/7d/c7/4cf3b585f6b07e6c801546b48ad0b7fa1063c5eaffa0654b63ba4829cb9f/attach-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c891884141f134066f547458ad4f2bec", "sha256": "18f2e86a7263406d3d97ed78db9f5c1cc7a07f9b1a488e76fe199d984f8b49b4" }, "downloads": -1, "filename": "attach-0.1.tar.gz", "has_sig": false, "md5_digest": "c891884141f134066f547458ad4f2bec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3871, "upload_time": "2018-08-11T06:51:07", "url": "https://files.pythonhosted.org/packages/69/7b/27795c87fe7c1d0380cdb8149c3526fc9c17a764e89689437e674da4fd00/attach-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "650102d8c5502674e28cfcfdf60bbba7", "sha256": "355d801bc94c778abf45e26eee11e79791db887461fd008b5dbe8ced92b98d60" }, "downloads": -1, "filename": "attach-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "650102d8c5502674e28cfcfdf60bbba7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4118, "upload_time": "2018-08-11T06:51:06", "url": "https://files.pythonhosted.org/packages/7d/c7/4cf3b585f6b07e6c801546b48ad0b7fa1063c5eaffa0654b63ba4829cb9f/attach-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c891884141f134066f547458ad4f2bec", "sha256": "18f2e86a7263406d3d97ed78db9f5c1cc7a07f9b1a488e76fe199d984f8b49b4" }, "downloads": -1, "filename": "attach-0.1.tar.gz", "has_sig": false, "md5_digest": "c891884141f134066f547458ad4f2bec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3871, "upload_time": "2018-08-11T06:51:07", "url": "https://files.pythonhosted.org/packages/69/7b/27795c87fe7c1d0380cdb8149c3526fc9c17a764e89689437e674da4fd00/attach-0.1.tar.gz" } ] }