Created
January 13, 2011 20:01
-
-
Save JeffSackmann/778484 to your computer and use it in GitHub Desktop.
turn a 2-d python matrix (list of lists) into a .csv file
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
## turn a 2-d python matrix (list of lists) into a .csv file | |
## see also gist: 778481 to reverse the process | |
def writeMatrixCSV(mx, fname): | |
## mx is a 2-d python matrix | |
## fname is the desired output filename | |
f = open(fname, 'w') | |
for r in mx: | |
tx = '' | |
i = 0 | |
while i < (len(r)-1): | |
tx += str(r[i]) | |
tx += ',' | |
i += 1 | |
try: tx += str(r[(len(r)-1)]) | |
except: pass | |
if tx == '': pass | |
else: tx += '\n' | |
f.write(tx) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment