Harry Percival Looks nice! Y u no namedtuple?
Kenneth Reitz Dictionaries are a much more predictable interface ;)
Kenneth Reitz Just because you can do something, doesn't mean you should!
>>> d = {'ñanáöß$': 1} >>> d {'ñanáöß$': 1} >>> d.keys() dict_keys(['ñanáöß$']) >>>
>>> collections.namedtuple("test", "$")
Traceback (most recent call last):
...
ValueError: Type names and field names can only contain alphanumeric characters and underscores: '$'The parent comments were discussing why choosing dicts over namedtuples for db-originated columns, and the fact that field names are restricted on namedtuples but not on dicts is a very compelling point.
Making examples usind dicts and explaining why namedtuples have restrictions is completely missing the point.
>>> d = {'ñanáöß$': 1}
d {'ñanáöß$': 1}
>>> d.keys()
dict_keys(['ñanáöß$'])This lib also looks brand new, so there is plenty of time for the community to optimize the hell out of it.
[1] https://github.com/python/cpython/blob/master/Lib/collection...
[1] https://github.com/python/cpython/blob/2.7/Python/ceval.c#L1...
[2] https://github.com/python/cpython/blob/master/Python/ceval.c...
>>> nt = namedtuple('nt', 'a b')
>>> nt10k = [nt(1, 2) for i in range(10000)]
>>> dict10k = [{'a':1, 'b':2} for i in range(10000)]
>>> timeit pickle.dumps(nt10k)
10 loops, best of 3: 26.3 ms per loop
>>> timeit pickle.dumps(dict10k)
100 loops, best of 3: 2.49 ms per loop
That seems inefficient. You're always going to have the same columns in each row, so storing column names for each row is a huge waste of memory. Django's "cursor.fetchall" returns a list of tuples, which seems to be a saner way to represent db rows in Python.