#first two elements of list legislators. #[[‘Bassett‘, ‘Richard‘, ‘1745-04-02‘, ‘M‘, ‘sen‘, ‘DE‘, ‘Anti-Administration‘, ‘1745‘], [‘Bland‘, ‘Theodorick‘, ‘1742-03-21‘, ‘M‘, ‘rep‘, ‘VA‘, ‘‘, ‘1742‘]] #1745 is extract from 1745-04-02 as the birth year, but not all elements have valid birth years. Some birth year is ""
for row in legislators: try: row[7]=int(row[7]) except Exception: row[7]=0
原文:http://www.cnblogs.com/arsh/p/5103689.html