用途
csv.DictReader:
import csvwith open('test.csv') as f: a = [{k: int(v) for k, v in row.items()} for row in csv.DictReader(f, skipinitialspace=True)]将导致:
[{'col2': 2, 'col3': 3, 'col1': 1}, {'col2': 5, 'col3': 6, 'col1': 4}]
用途
csv.DictReader:
import csvwith open('test.csv') as f: a = [{k: int(v) for k, v in row.items()} for row in csv.DictReader(f, skipinitialspace=True)]将导致:
[{'col2': 2, 'col3': 3, 'col1': 1}, {'col2': 5, 'col3': 6, 'col1': 4}]