mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 15:00:19 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f17ccf445 | |||
| 9b3268f0ad | |||
| f386ef8ac8 | |||
| e8f5e023c4 | |||
| 81445aeec8 | |||
| f94a236122 | |||
| bfbb7c626f | |||
| be0f77f9ee |
+12
-3
@@ -1,11 +1,20 @@
|
||||
History
|
||||
=======
|
||||
|
||||
0.6.4 (2010-09-13)
|
||||
0.7.0 (2010-09-20)
|
||||
------------------
|
||||
|
||||
* Updated unicode export for XLS
|
||||
* More exhaustive unit tests
|
||||
* Renamed DataBook Databook for consistiency.
|
||||
* Export properties changed to methods (XLS filename / StringIO bug).
|
||||
* Optional Dataset.xls(path='filename') support (for writing on windows).
|
||||
* Added utf-8 on the worksheet level.
|
||||
|
||||
|
||||
0.6.4 (2010-09-19)
|
||||
------------------
|
||||
|
||||
* Updated unicode export for XLS.
|
||||
* More exhaustive unit tests.
|
||||
|
||||
|
||||
0.6.3 (2010-09-14)
|
||||
|
||||
+5
-5
@@ -70,7 +70,7 @@ JSON!
|
||||
+++++
|
||||
::
|
||||
|
||||
>>> print data.json
|
||||
>>> print data.json()
|
||||
[
|
||||
{
|
||||
"last_name": "Adams",
|
||||
@@ -89,7 +89,7 @@ YAML!
|
||||
+++++
|
||||
::
|
||||
|
||||
>>> print data.yaml
|
||||
>>> print data.yaml()
|
||||
- {age: 90, first_name: John, last_name: Adams}
|
||||
- {age: 83, first_name: Henry, last_name: Ford}
|
||||
|
||||
@@ -97,7 +97,7 @@ CSV...
|
||||
++++++
|
||||
::
|
||||
|
||||
>>> print data.csv
|
||||
>>> print data.csv()
|
||||
first_name,last_name,age
|
||||
John,Adams,90
|
||||
Henry,Ford,83
|
||||
@@ -106,8 +106,8 @@ EXCEL!
|
||||
++++++
|
||||
::
|
||||
|
||||
>>> open('people.xls').write(data.xls)
|
||||
|
||||
>>> data.xls('people.xls')
|
||||
|
||||
It's that easy.
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ if sys.argv[-1] == "publish":
|
||||
|
||||
setup(
|
||||
name='tablib',
|
||||
version='0.6.4',
|
||||
version='0.7.0',
|
||||
description='Format agnostic tabular data library (XLS, JSON, YAML, CSV)',
|
||||
long_description=open('README.rst').read() + '\n\n' +
|
||||
open('HISTORY.rst').read(),
|
||||
|
||||
+30
-26
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
import csv
|
||||
import cStringIO
|
||||
import StringIO
|
||||
import random
|
||||
|
||||
import simplejson as json
|
||||
@@ -21,8 +21,8 @@ from helpers import *
|
||||
# __all__ = ['Dataset', 'DataBook']
|
||||
|
||||
__name__ = 'tablib'
|
||||
__version__ = '0.6.4'
|
||||
__build__ = 0x000604
|
||||
__version__ = '0.7.0'
|
||||
__build__ = 0x000700
|
||||
__author__ = 'Kenneth Reitz'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright 2010 Kenneth Reitz'
|
||||
@@ -149,29 +149,25 @@ class Dataset(object):
|
||||
self.__headers = None
|
||||
|
||||
|
||||
|
||||
@property
|
||||
def dict(self):
|
||||
"""Returns python dict of Dataset."""
|
||||
return self._package()
|
||||
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
"""Returns JSON representation of Dataset."""
|
||||
return json.dumps(self.dict)
|
||||
|
||||
|
||||
@property
|
||||
def yaml(self):
|
||||
"""Returns YAML representation of Dataset."""
|
||||
return yaml.dump(self.dict)
|
||||
|
||||
|
||||
@property
|
||||
def csv(self):
|
||||
"""Returns CSV representation of Dataset."""
|
||||
stream = cStringIO.StringIO()
|
||||
stream = StringIO.StringIO()
|
||||
_csv = csv.writer(stream)
|
||||
|
||||
for row in self._package(dicts=False):
|
||||
@@ -180,19 +176,23 @@ class Dataset(object):
|
||||
return stream.getvalue()
|
||||
|
||||
|
||||
@property
|
||||
def xls(self):
|
||||
def xls(self, path=None):
|
||||
"""Returns XLS representation of Dataset."""
|
||||
stream = cStringIO.StringIO()
|
||||
|
||||
wb = xlwt.Workbook()
|
||||
wb = xlwt.Workbook(encoding='utf8')
|
||||
ws = wb.add_sheet(self.title if self.title else 'Tabbed Dataset')
|
||||
|
||||
for i, row in enumerate(self._package(dicts=False)):
|
||||
for j, col in enumerate(row):
|
||||
ws.write(i, j, col.decode('utf8'))
|
||||
ws.write(i, j, col)
|
||||
|
||||
wb.save(stream)
|
||||
return stream.getvalue()
|
||||
if path:
|
||||
wb.save(path)
|
||||
return True
|
||||
else:
|
||||
stream = StringIO.StringIO()
|
||||
wb.save(stream)
|
||||
return stream.getvalue()
|
||||
|
||||
|
||||
def append(self, row=None, col=None):
|
||||
@@ -227,7 +227,7 @@ class Dataset(object):
|
||||
pass
|
||||
|
||||
|
||||
class DataBook(object):
|
||||
class Databook(object):
|
||||
"""A book of Dataset objects.
|
||||
Currently, this exists only for XLS workbook support.
|
||||
"""
|
||||
@@ -267,12 +267,11 @@ class DataBook(object):
|
||||
return len(self._datasets)
|
||||
|
||||
|
||||
@property
|
||||
def xls(self):
|
||||
def xls(self, path=None):
|
||||
"""Returns XLS representation of DataBook."""
|
||||
|
||||
stream = cStringIO.StringIO()
|
||||
wb = xlwt.Workbook()
|
||||
|
||||
wb = xlwt.Workbook(encoding='utf8')
|
||||
|
||||
for i, dset in enumerate(self._datasets):
|
||||
ws = wb.add_sheet(dset.title if dset.title else 'Sheet%s' % (i))
|
||||
@@ -280,20 +279,25 @@ class DataBook(object):
|
||||
#for row in self._package(dicts=False):
|
||||
for i, row in enumerate(dset._package(dicts=False)):
|
||||
for j, col in enumerate(row):
|
||||
ws.write(i, j, str(col))
|
||||
ws.write(i, j, col)
|
||||
|
||||
|
||||
|
||||
if path:
|
||||
wb.save(path)
|
||||
return True
|
||||
else:
|
||||
stream = cStringIO.StringIO()
|
||||
wb.save(stream)
|
||||
return stream.getvalue()
|
||||
|
||||
wb.save(stream)
|
||||
return stream.getvalue()
|
||||
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
"""Returns JSON representation of Databook."""
|
||||
|
||||
return json.dumps(self._package())
|
||||
|
||||
|
||||
@property
|
||||
def yaml(self):
|
||||
"""Returns YAML representation of Databook."""
|
||||
|
||||
|
||||
+5
-5
@@ -167,7 +167,7 @@ class TablibTestCase(unittest.TestCase):
|
||||
csv += str(col) + ','
|
||||
csv = csv.strip(',') + '\r\n'
|
||||
|
||||
self.assertEqual(csv, self.founders.csv)
|
||||
self.assertEqual(csv, self.founders.csv())
|
||||
|
||||
|
||||
def test_unicode_append(self):
|
||||
@@ -176,10 +176,10 @@ class TablibTestCase(unittest.TestCase):
|
||||
new_row = ('å', 'é')
|
||||
data.append(new_row)
|
||||
|
||||
data.json
|
||||
data.yaml
|
||||
data.csv
|
||||
data.xls
|
||||
data.json()
|
||||
data.yaml()
|
||||
data.csv()
|
||||
data.xls()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user