Skip to main content

Turn Python Dictionary into reddit table

Project description

Usage

createRedditTable(obj, headers=[], justifyString='c', outputfile='', index='index', includeIndex=False)

Basic Usage just pass in a dictionary and you get a table output to console with no ordering of headers, all columns center justified and no index included

import rtablify as rtablify

dictionary = {"apple": {'a': 1, 'b' : 2}, "banana" : {'a': 4, 'b' : 6}}
rtablify.createRedditTable(dictionary)

Output:
a|b
:-:|:-:
1|2
4|6

Include a list of headers to enforce a header order

rtablify.createRedditTable(dictionary, headers = ['b', 'a']])

Output:
b|a
:-:|:-:
2|1
6|4

Include a justify string of either 'r' for right 'c' for center and 'l' to justify columns, if you don't provide enough characters it will fill with the last in the string.

So if you had 7 columns and wanted the first left justified and all the rest centered you could pass in a string of 'lc' or 'lcccccc' both would have the same results.

Bug to fix in future relases is handle if justifyString is too long for now don't do that.

rtablify.createRedditTable(dictionary, justifyString = 'll')

Output:
a|b
--:|--:
1|2
4|6

If you include an outputfile name it will be created in the directory with a name provided and will not print to the console.

If leave on includeIndex = True (default false) The index will added into the table. If you do not specify an index name it will be called index. If you want an index it is best to include a header list to let the function know where you want the index to be.

rtablify.createRedditTable(dictionary, headers= ['index','a','b'], includeIndex = True)

Output:
index|a|b
:-:|:-:|:-:
apple|1|2
banana|4|6

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

reddit-tablify-1.0.1.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

reddit_tablify-1.0.1-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

Supported by

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