Last active
December 15, 2015 09:19
-
-
Save gpjt/5237115 to your computer and use it in GitHub Desktop.
Loading CSVs as tuples
This file contains 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
def load_file(filename): | |
fp = open(filename, 'Ur') | |
data_list = [] | |
for line in fp: | |
data_list.append(tuple(line.strip().split(','))) | |
fp.close() | |
return data_list | |
def save_file(filename, data_list): | |
fp = open(filename, 'w') | |
for line in data_list: | |
fp.write(','.join(line) + '\n') | |
fp.close() | |
if __name__ == "__main__": | |
print "Loading data from file..." | |
data_list = load_file("sample.csv") | |
print "Data loaded and parsed, it is", data_list | |
save_file("updated_sample.csv", data_list) | |
print "Data saved." |
This file contains 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
a | b | c | d | e | f | g | |
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment