Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More documentation and tests

  • Loading branch information...
commit ebd815e70525eceb37217d98a0bb92bb3326f0a3 1 parent 160496f
@eyeseast authored
Showing with 42 additions and 3 deletions.
  1. +42 −3 README.markdown
View
45 README.markdown
@@ -2,6 +2,7 @@ This is a Python implementation of ProPublica's [TableFu](http://propublica.gith
This API is similar, though following Python conventions.
Usage:
+------
>>> from table_fu import TableFu
>>> csv = open('tests/test.csv')
@@ -32,7 +33,21 @@ Usage:
>>> print row['Author']
James Joyce
- # tables can also be faceted
+ # sort rows
+ >>> table.sort('Author')
+ >>> table.rows
+ [<Row: James Joyce, Ulysses, 644, Modernism>,
+ <Row: Nicholson Baker, Mezannine, 150, Minimalism>,
+ <Row: Samuel Beckett, Malone Muert, 120, Modernism>,
+ <Row: Vladimir Sorokin, The Queue, 263, Satire>]
+
+ # sorting is stored
+ table.options['sorted_by']
+ {'Author': {'reverse': False}}
+
+ # which is handy because...
+
+ # tables can also be faceted (and options are copied to new tables)
>>> for t in table.facet_by('Style'):
... print t.faceted_on
... t.table
@@ -45,10 +60,34 @@ Usage:
[['Vladimir Sorokin', 'The Queue', '263', 'Satire']]
+Formatting
+----------
+
+Filters are just functions that take a value and some number of positional arguments.
+New filters can be registered with the included Formatter class.
+
+ >>> from table_fu.formatting import Formatter
+ >>> format = Formatter()
+ >>> def capitalize(value, *args):
+ ... return str(value).capitalize()
+ >>> format.register(capitalize)
+ >>> print format('foo', 'capitalize')
+ Foo
+
+Cells can be formatted according to rules of the table (which carry over if the table is faceted):
+
+ >>> table = TableFu(open('tests/sites.csv'))
+ >>> table.columns
+ ['Name', 'URL', 'About']
+ >>> table.formatting = {
+ ... 'Name': {'filter': 'link', 'args': ['URL']}
+ ... }
+ >>> print table[0]['Name']
+ <a href="http://www.chrisamico.com" title="ChrisAmico.com">ChrisAmico.com</a>
+
+
To do:
- - formatting
- - options (need to figure out how soon options passed to TableFu.__init__ are executed)
- output (this should, eventually, output HTML)
More documentation coming.
Please sign in to comment.
Something went wrong with that request. Please try again.