0
IOError for mac when open .csv file with python
I have tried homedir and says.path.append, but there still an error showing no file. The path is ‘Users/myname/Desktop/data.csv’/ Does anyone know how to deal with the problem 😭
3 Antworten
+ 2
Output the string of the full filename, including path (from your code).
Then from the Terminal on your Mac, type 'ls ' followed by the full filename including path. Does that work?
Just trying to double check you're using the correct path and filename.
+ 1
thx!
0
# coding=UTF-8
import csv
import os
#import time
import sys
#output velocity and time
from StdSuites import row
def velocity_cal(old_file, new_file, old_reader=None, new_reader=None):
old_reader = open('old_file','r')
line = len(old_reader.readlines())
for row in line:
if((row[2] in old_reader == 113.828428) and (row[3] in old_reader == 22.782413)) or\
((row[2] in old_reader == 114.038520) and (row[3] in old_reader == 22.556953)) or\
((row[2] in old_reader == 113.991329) and (row[3] in old_reader == 22.555888)) or\
((row[2] in old_reader == 114.013536) and (row[3] in old_reader ==22.553878)) or\
((row[2] in old_reader == 114.013980) and (row[3] in old_reader == 22.575338)):
new_reader = open('new_file.csv', 'w')
writer = csv.writer(new_reader)
for row in old_reader:
writer.writerow(row)
writer.close()
old_reader.close()
sys.path.append('/Users/guoxuanjun/Desktop/data0325.csv')
sys.path.append('/Users/guoxuanjun/Desktop/data0325_ana.csv')
homedir = os.getcwd()+'/Users/guoxuanjun/Desktop/'
homedir_new = os.getcwd()+'/Users/guoxuanjun/Desktop/'
velocity_cal(homedir+'data0325.csv',homedir_new+'data0325_ana.csv')