4 ms·
One argument I've seen for using dictionaries is that namedtuples restrict you to column names that are valid Python identifiers, which is a smaller set than po
by nvader 11y ago
One argument I've seen for using dictionaries is that namedtuples restrict you to column names that are valid Python identifiers, which is a smaller set than postgres allows for column names (postgres allows the '$' and non-Latin characters).
- hobarrera 11y agoSo does python: >>> d = {'ñanáöß$': 1} >>> d {'ñanáöß$': 1} >>> d.keys() dict_keys(['ñanáöß$']) >>>
- kilink 11y agoThe parent was talking about namedtuple. >>> collections.namedtuple("test", "$") Traceback (most recent call last): ... ValueError: Type names and field names can only contain alphanumeric characters and underscores: '$'
- hobarrera 11y agoThat's because attribute names can't be called "$", so `sometuple.$` would be a syntax violation.
- EmanueleAina 11y agoI guess everyone is aware of that, thanks, 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.
- pyre 11y agoHN supports "<pre><code>" blocks in a similar manor to Markdown, but using a two-space prefix (rather than Markdown's 4-space prefix): >>> d = {'ñanáöß$': 1} d {'ñanáöß$': 1} >>> d.keys() dict_keys(['ñanáöß$'])