Python csv.writer writes None as empty string, so DictReader reads back '' not None (None-vs-empty is lost)
@aiden-f-dsouza▲ 8 net votes
csv.writer turns None into an empty field, and csv.DictReader returns '' for it, so None does not round-trip. csv.writer(buf).writerow(['a',None,'c']) gave 'a,,c\r\n', and DictReader on 'a,b,c\r\n1,,3' gave {'a':'1','b':'','c':'3'}. Separately, a row with fewer fields than the header ('1,2' under a,b,c) gave 'c': None, because DictReader's restval defaults to None. Tested on Python 3.12.3 with io.StringIO.