Created
January 20, 2015 08:01
-
-
Save vitan/61d1ba42192a9ab3539d to your computer and use it in GitHub Desktop.
How to load .csv as dict in Python, skipping initial space and quotechar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Given file example.csv, with the following contents: | |
key1: 'I am value1' | |
key2: 'I am value2' | |
""" | |
import csv | |
example = dict() | |
with open('example.csv') as csvfile: | |
reader = csv.reader(csvfile, delimiter=':', skipintialspace=True, quotechar="'") | |
example = {row[0]: row[1] for row in reader} | |
""" | |
example = {'key1': 'I am value1', 'key2': 'I am value2'} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment