astropy/astropy — pull request #726 by taldcroft (2013-02-04 22:10:40+00:00)
Title: Table: suggestion to create new column upon assignment to non-existing one

Hi,

I've started using the Table class and really like it, but one annoyance is that one has to know whether a column exists before assigning to it, as, when it does not, an exception is thrown. Would it be an idea to try to create the column automatically (i.e., have behaviour more closely similar to dict),

i.e.,

mytable['new'] = mytable['old']
or
mytable['new'] = 'test'

would create a new column. A very simple (and likely imperfect) implementation could replace the current __setitem__ with:

```
def __setitem__(self, item, value):
try:
self._data[item] = value
except (ValueError, KeyError, TypeError):
if hasattr(value,'__len__') and len(value) == len(self):
self.add_column(Column(item, value))
else:
self.add_column(Column(item, [value]*len(self)))
except:
raise
```