diff options
author | Tobias Klauser <tobias.klauser@uzh.ch> | 2013-02-11 17:05:57 +0100 |
---|---|---|
committer | Tobias Klauser <tobias.klauser@uzh.ch> | 2013-02-11 17:05:57 +0100 |
commit | dfbc6a61a0ebbaecbb84000157c16fa8eb16bc55 (patch) | |
tree | d0a5e0148260074de42537e6787b996169b814d2 /scripts | |
parent | b37e131a1e153cf72fbdba7c267d1742a1e40cd3 (diff) |
scripts: Auto-detect CSV format in tools handling CSV input
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/csv2sto.py | 6 | ||||
-rwxr-xr-x | scripts/plotcsv.py | 5 |
2 files changed, 9 insertions, 2 deletions
diff --git a/scripts/csv2sto.py b/scripts/csv2sto.py index 4275fb1..c43a990 100755 --- a/scripts/csv2sto.py +++ b/scripts/csv2sto.py @@ -121,7 +121,11 @@ def main(): fd_sto.write("\n") fds_csv = [ open(f_csv, 'r') for f_csv in fs_csv ] - crs = [ csv.reader(fd_csv, delimiter=',') for fd_csv in fds_csv ] + crs = [] + for fd_csv in fds_csv: + dialect = csv.Sniffer().sniff(fd_csv.read(1024)) + fd_csv.seek(0) + crs.append(csv.reader(fd_csv, dialect)) times = np.zeros((tot_nRows, len(fds_csv))) vals = np.zeros((tot_nRows, len(fds_csv))) diff --git a/scripts/plotcsv.py b/scripts/plotcsv.py index fd6d084..1d26354 100755 --- a/scripts/plotcsv.py +++ b/scripts/plotcsv.py @@ -41,7 +41,10 @@ def plot(x, y, x_max, y_max, x_name, y_name, title, cubic, linear, xnew=None, f= def read_and_plot_csv(csv_file, cubic, linear, x_max=X_MAX, y_max=Y_MAX): print("Reading data...") - reader = csv.reader(open(csv_file, 'r'), delimiter=',') + cf = open(csv_file, 'r') + dialect = csv.Sniffer().sniff(cf.read(1024)) + cf.seek(0) + reader = csv.reader(cf, dialect) x_name,y_name = reader.next() # header line X = np.array([[float(_x), float(_y)] for _x,_y in reader ]) |