Programming Language that is Spreadsheet/Table Based
Gerard Flanagan
grflanagan at yahoo.co.uk
Sat Nov 4 02:44:20 EST 2006
James Stroud wrote:
> I have spent a lot of time making a "Table"
> class over about the last year and a half, but I'm not sure what might
> be an intuitive interface for most people. First, I think it should work
> like a "sorted" dictionary of lists, but, at the same time, a list of
> sorted dictionaries. I also want *shorthand* for selection.
>
> For example, does the output below look like an intuitive interface? Or,
> more likely, how many people get squeamish when they see this interface?
> Do these squeamish people have any better ideas? This is a taste of how
> my Table class currently behaves:
>
> py> print t # dependent on its property t.format
> Last First Age
> Barker Bob 204
> Burnet Carol 64
> Danson Ted 54
> Cooper Alice 78
> py> t.headings()
> ("Last", "First", "Age")
> py> t.get_row(1)
> ['Burnet', 'Carol', 64]
> py> t[1]
> ['Burnet', 'Carol', 64]
> py> t.get_column('Last')
> ['Barker', 'Burnet', 'Danson', 'Cooper']
+1 from me up to here
> py> # the following is probably the trickiest, should it return a Table
> py> # should it be illegal?
> py> # should t['Last'] be the way to take the "slice" and get the col?
> py> t[None, 'Last'] # 1d slice returns list (2nd dim. explicit)
> ['Barker', 'Burnet', 'Danson', 'Cooper']
I can imagine manipulating columns at the Table creation stage -
insert, append, delete column - but after that I think you would be
dealing with rows more often. Personally, if I needed columns I would
be happier with a list comprehension:
[ (row['Last'], row['Age']) for row in t ] etc.
eg. like:
http://buzhug.sourceforge.net/
> py> t2 = t[1:3, ('First', 'Age')] # 2d slice returns a new Table
> py> t3 = t[1:3,'First':'Age'] # shorthand to take a swath of columns
> py> t3 = t[1:3, 0:2] # if we know what column numbers we want instead
t[1:3][0:2] and so on would be more intuitive to me, possibly
t[1:3]['First':'Age']
> Please don't criticize unless you have a better idea
> about the API of a Table. I want to hear genuine and concrete ideas and
> not abstruse pontification about programming or design! Statements of "I
> wouldn't do this thing here" should be immediately followed by
> "--rather, I would do this other thing for which I've created a concrete
> example below."
chill...
Gerard
More information about the Python-list
mailing list