3 ms·
TabLib: Pythonic Tabular Data Library
- zrail 16y agoThis looks pretty interesting. We have a similar home-grown library at work with a lot more structure built into the headers. For example, a header can specify what datatype the column is (number, text, icon), as well as a title in various formats (html, text, spreadsheet). The basic idea is the same, though. Take a bunch of data, throw it in a container object, and export it in a bunch of different formats.
- kennethreitz 16y agoI'm glad you find it interesting/useful. I plan to add column types further down the road. But first, pluggable format support, importing, and cli interface will be written.
- benhoyt 16y agoLooks like a nice little module. However, just some comments on the (lack of) Pythonicity in this function: def is_string(obj): """Tests if an object is a string""" return True if type(obj).__name__ == 'str' else False First, you don't need the "True if ... else False", because == is already a boolean operator which returns True or False. Also, you don't need to look at the type's __name__. You can just say: type(obj) == str But Python already has an isinstance() function which will also work properly with subclasses of str, so suddenly you don't need the is_string() helper function anymore, and it becomes: isinstance(obj, str) (Though you should probably use "basestring" in Python 2.x so it works with Unicode keys too.)
- kennethreitz 16y agoThanks for the input. The whole thing is def a work in progress. I put it together in about 4 hours, and that function in particular was some copy pasta from a project a few years ago. No worries, updates to come :)