mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 23:10:17 +00:00
Time for some testing.
This commit is contained in:
+13
-4
@@ -9,7 +9,9 @@
|
||||
|
||||
import csv
|
||||
|
||||
from helpers import *
|
||||
|
||||
__all__ = ['Dataset', 'source']
|
||||
|
||||
__version__ = '0.0.3'
|
||||
__build__ = '0x000003'
|
||||
@@ -17,8 +19,6 @@ __author__ = 'Kenneth Reitz'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright 2010 Kenneth Reitz'
|
||||
|
||||
__all__ = ['Dataset', 'source']
|
||||
|
||||
|
||||
|
||||
class Dataset(object):
|
||||
@@ -39,7 +39,15 @@ class Dataset(object):
|
||||
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._data[key]
|
||||
|
||||
if is_string(key):
|
||||
if key in self.headers:
|
||||
pos = self.headers.index(key) # get 'key' index from each data
|
||||
return [row[pos] for row in self._data]
|
||||
else:
|
||||
raise KeyError
|
||||
else:
|
||||
return self._data[key]
|
||||
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
@@ -93,7 +101,8 @@ class Dataset(object):
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
pass
|
||||
if self.headers:
|
||||
pass
|
||||
|
||||
|
||||
@property
|
||||
|
||||
+6
-1
@@ -15,6 +15,11 @@ class Object(object):
|
||||
|
||||
def piped():
|
||||
"""Returns piped input via stdin, else False"""
|
||||
|
||||
with sys.stdin as stdin:
|
||||
return stdin.read() if not stdin.isatty() else None
|
||||
|
||||
|
||||
def is_string(obj):
|
||||
"""Tests if an object is a string"""
|
||||
|
||||
return True if type(obj).__name__ == 'str' else False
|
||||
Reference in New Issue
Block a user