{"id":16398220,"url":"https://github.com/bradjc/python-dataprint","last_synced_at":"2025-12-06T01:02:42.273Z","repository":{"id":7996133,"uuid":"9403157","full_name":"bradjc/python-dataprint","owner":"bradjc","description":"Python module to print data to a file in a nice way.","archived":false,"fork":false,"pushed_at":"2017-07-11T23:26:20.000Z","size":29,"stargazers_count":1,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-16T21:43:13.806Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bradjc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-12T20:34:09.000Z","updated_at":"2017-05-26T20:48:48.000Z","dependencies_parsed_at":"2022-08-28T07:51:31.316Z","dependency_job_id":null,"html_url":"https://github.com/bradjc/python-dataprint","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradjc%2Fpython-dataprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradjc%2Fpython-dataprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradjc%2Fpython-dataprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradjc%2Fpython-dataprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradjc","download_url":"https://codeload.github.com/bradjc/python-dataprint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238347819,"owners_count":19456999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T05:12:09.030Z","updated_at":"2025-10-26T14:31:29.473Z","avatar_url":"https://github.com/bradjc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"python-dataprint\n================\n\n[![Build Status](https://travis-ci.org/bradjc/python-dataprint.svg?branch=master)](https://travis-ci.org/bradjc/python-dataprint)\n\nPython module to print data to a file in a nice way. Usually data processing\nscripts write data to a file, but it is a hassle to format it nicely each\ntime. So data files end up looking like:\n\n    x y z\n    50 678 9\n    5643 908 44\n    321 2 2\n\nwhich I find very hard to read. This module lets you take\n\n```python\ndata = [\n ['x', 'y', 'z'],\n [50, 678, 9],\n [5643, 908, 44],\n [321, 2, 2]\n]\n```\n\nthen do:\n\n```python\nimport dataprint\ndataprint.to_newfile(\"xyz.dat\", data)\n```\n\nto get:\n\n    # x   y    z\n    50    678  9\n    5643  908  44\n    321   2    2\n\nMuch better.\n\n\nInstall\n-------\n\n    sudo pip install dataprint\n\nOR\n\n    git clone https://github.com/bradjc/python-dataprint.git\n    cd python-dataprint\n    sudo python setup.py install\n\nUsage\n-----\n\nDataprint provides three easy functions to use:\n\n    to_string (data, tabwidth=0, min_padding=2, separator='_', columns=False, comments=None, comment_lead='# ')\n    to_newfile (filename, data, tabwidth=0, min_padding=2, separator='_', columns=False, overwrite=False, comments=None, comment_lead='# '):\n    to_file (open_file, data, tabwidth=0, min_padding=2, separator='_', columns=False, comments=None, comment_lead='# ')\n\nThe options:\n\n    data:         A 2D array of data that should be formatted\n    filename:     string name of a file the data should be put in\n    open_file:    a file descriptor the data should be added to\n    tabwidth:     if 0, use spaces as the column separators.\n                  if \u003e1, use tabs of tabwidth length to separate columns\n    min_padding:  minimum number of spaces between columns in the output\n    separator:    string that will replace whitespace in the column data.\n                  This prevents spaces in data from creating more columns.\n    columns:      Set if data array is columnar instead of in row.\n    overwrite:    whether or not to overwrite a file if it exists\n    comments:     A string or array of strings to print as comments first.\n    comment_lead: Prefix all comments with this string. None will disable commenting.\n\n\n\nExamples\n--------\n\n### Example 1\n\nBasic usage.\n\n```python\nimport dataprint\n\ndata = [['Color', 'Length'],\n        ['blue', 4],\n        ['red', 3]]\n\nprint dataprint.to_string(data)\n```\n\nWill print:\n\n    # Color  Length\n    blue     4\n    red      3\n\n\n\n### Example 2\n\nChange the settings.\n\n```python\nimport dataprint\n\ndata = [['Color', 'Length'],\n        ['blue', 4],\n        ['red', 3],\n        ['orange yellow', 13]]\n\nprint dataprint.to_string(data, min_padding=4, separator='-')\n```\n\n    # Color          Length\n    blue             4\n    red              3\n    orange-yellow    13\n\n\n### Example 3\n\nOutput to a file.\n\n```python\nimport dataprint\n\ndata = [['Color', 'Length'],\n        ['blue', 4],\n        ['red', 3]]\n\ndataprint.to_newfile(filename='example3.dat', data=data)\n```\n\nWill create `example3.dat` containing:\n\n    # Color  Length\n    blue     4\n    red      3\n\n\n### Example 4\n\nYou may want to put the formatted data into an already opened file.\n\n```python\nimport dataprint\n\ndata = [['Color', 'Length'],\n        ['blue', 4],\n        ['red', 3]]\n\nfd = open('example4.dat', 'w')\n\nfd.write('# This data file is for example 4.\\n\\n')\n\ndataprint.to_file(open_file=fd, data=data)\n```\n\nThis will create `example4.dat` containing:\n\n    # This data file is for example 4.\n\n    # Color  Length\n    blue     4\n    red      3\n\n\n### Example 5\n\nYour data may be in columns instead of rows. To use this data, set `columns` to\n`TRUE`.\n\n```python\nimport dataprint\n\nx = [1, 2, 3]\ny = [10, 20, 30]\n\nprint dataprint.to_string(data=[x, y], columns=True)\n```\nOutput:\n\n    1  10\n    2  20\n    3  30\n\n\n### Example 6\n\nYou may want to add extra notes to your data file, or have complicated data\nthat requires some extra explanation.\n\n```python\nimport dataprint\nimport time\n\ndata = [['blue', 4],\n        ['red', 3]]\n\nprint dataprint.to_string(data, comments='Generated at {}'.format(time.asctime()))\n```\n\nWill print:\n\n    # Generated at Tue Oct  6 12:15:45 2015\n    blue   4\n    red    3\n\n\nChangelog\n---------\n\n### Version 1.0\nNo longer a package (just use `import dataprint`).\nPython 3 support.\n\n### Version 0.3\nAdded support for column based data.\n\n### Version 0.2\nAdded many tests, more error checking, and a separator replacement for spaces.\n\n### Version 0.1\nInitial release. Supports data layouts of lists of lists, separates with tabs\nor spaces, and can write to a string or file.\n\nTo Do\n-----\n\n  - Document the thing\n  - Lot more testing with different data inputs\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradjc%2Fpython-dataprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradjc%2Fpython-dataprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradjc%2Fpython-dataprint/lists"}