Skip to content

Commit

Permalink
Trying to wire up some python 2/3 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Nov 25, 2018
1 parent 5a79080 commit e4b1ee3
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions epregressions/diffs/mycsv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
"""my csv functions
"""

# Copyright (C) 2009 Santosh Philip
# This file is part of mathdiff.
#
Expand Down Expand Up @@ -38,24 +35,26 @@ def readcsv(filename):
"""read csv file fname into a matrice mat
Also reads a string instead of a file
"""
is_file = False
try:
f = open(filename)
reader = csv.reader(f) # if it is a file
is_file = True
with open(filename) as f:
reader = csv.reader(f) # if it is a file
data = []
for line in reader:
# print ("%s : %s" % (filename, line))
data.append(line)
return data
except:
try:
string = StringIO(filename)
reader = csv.reader(string) # if it is a string
lines = filename.split('\n')
data = []
for line in lines:
if line.strip() == '':
break
# print ("%s : %s" % (filename, line))
data.append(line.strip().split(','))
return data
except:
raise BadInput('csv source is neither a file nor a file object')
data = []
for line in reader:
# print ("%s : %s" % (filename, line))
data.append(line)
if is_file:
f.close()
return data


def writecsv(mat, outfile=None, mode='w'):
Expand Down

0 comments on commit e4b1ee3

Please sign in to comment.