{ "info": { "author": "CBWhiz", "author_email": "CBWhiz@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Development Status :: 7 - Inactive", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "DocReader\n\nA utility for reading a CSV file and mapping it's contents to python objects\nbased on the field names in the document.\n\nContains classes for reading loosly structured documents containing rows of \ntext (eg. CSV files) and turning them into slightly higher level lists of\ndictionaries.\n\nTypical usage is to create a subclass of DocReader and define the cols attribute\nonce. To use it, instantiate the subclass with an open file-like object (that \nsupports the iterator protocol and returns a full line of text on each next()\ncall).\n\nIterating over the DocReader subclass instance will then yield a dict where the\nkeys are as defined in the cols attribute and the values are the cell's logical\nvalues that have passed through the correct conversion function.\n\nThe cols attribute is itself is either a list of column names or a dictionary \nmapping keys (which will be used as the keys in the final returned data) to an \noptions dictionary for that column.\n\nAn options dictionary can have the following keys:\n - column: The name of the column as it appears in the document\n - convert: A callable that will be called with the string associated with\n the data in this cell. Often a type (eg int, float) or a lambda.\n\n>>> import decimal\n>>> def _price(val):\n... txt = val.replace('$', '').strip().lower()\n... txt = txt or None\n... return decimal.Decimal(txt)\n...\n>>> class MyReader(DocReader):\n... cols = dict(\n... a = dict(column='a', convert=int),\n... q = dict(column='b'),\n... c = dict(column='c', convert=lambda x: int(x)),\n... price = dict(convert=_price),\n... )\n...\n>>> import StringIO\n>>> #Ignore the use of chr(10), doctest doesn't like \\n.\n>>> list(MyReader(StringIO.StringIO(\"a,b,c,price\" + chr(10) + \"1,2,3,$45.6\" + chr(10) + \"4,5,6,$55\")))\n[{u'a': 1, u'q': u'2', u'c': 3, u'price': Decimal('45.6')}, {u'a': 4, u'q': u'5', u'c': 6, u'price': Decimal('55')}]\n>>> list(MyReader(StringIO.StringIO(\"a,b\" + chr(10) + \"1,2\")))\nTraceback (most recent call last):\n...\nMissingColumnException: Columns missing from input: c, price", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/CBWhiz/docreader", "keywords": "csv dictreader docreader", "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "docreader", "package_url": "https://pypi.org/project/docreader/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/docreader/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/CBWhiz/docreader" }, "release_url": "https://pypi.org/project/docreader/1.0/", "requires_dist": null, "requires_python": null, "summary": "A better csv.DictReader (supporting UTF-8 and type conversion)", "version": "1.0" }, "last_serial": 753844, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "7d180d6c376b2206d0d128e04cc55005", "sha256": "e770f8742de05d10d1c848592a90db1803cf2f52aaad92dab92b8d8fac221361" }, "downloads": -1, "filename": "docreader-1.0.tar.gz", "has_sig": false, "md5_digest": "7d180d6c376b2206d0d128e04cc55005", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3360, "upload_time": "2013-06-05T21:45:14", "url": "https://files.pythonhosted.org/packages/18/33/0f8e08bb3b0b3e4488b0eb9f610ee1111b667f676b4ff3a3d4fbf4177090/docreader-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7d180d6c376b2206d0d128e04cc55005", "sha256": "e770f8742de05d10d1c848592a90db1803cf2f52aaad92dab92b8d8fac221361" }, "downloads": -1, "filename": "docreader-1.0.tar.gz", "has_sig": false, "md5_digest": "7d180d6c376b2206d0d128e04cc55005", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3360, "upload_time": "2013-06-05T21:45:14", "url": "https://files.pythonhosted.org/packages/18/33/0f8e08bb3b0b3e4488b0eb9f610ee1111b667f676b4ff3a3d4fbf4177090/docreader-1.0.tar.gz" } ] }