so I want to use the csv module in order to read in some csv.files but I get the following errors with the given code:
########################### IMPORT MODULES ############################
import sys, time, glob, os, csv, student
######################### DEFINE PARAMETERS ###########################
timings_csv_file = './timings.csv'
inputs_csv_file = './inputs.csv'
testing_pair_csv_file = './testing_pair.csv'
############## LOAD TIMINGS INFORMATION AND TEST PAIR #################
csv_reader = csv.reader(open(timings_csv_file, 'rb'), delimiter=',')
timings = [int(element) for element in csv_reader.next()]
csv_reader = csv.reader(open(testing_pair_csv_file, 'rb'), delimiter=',')
testing_pair = [long(element) for element in csv_reader.next()]
csv_reader = csv.reader(open(inputs_csv_file, 'rb'), delimiter=',')
inputs = [long(element) for element in csv_reader.next()]
##################### PERFORM TIMING ATTACK ###########################
key = student.perform_timing_attack(inputs, timings, testing_pair)
######################## OUTPUT RESULTS ###############################
keyhex = ",".join(["%02X" % (key >> 64-(8*(i+1)) & 0x00000000000000FF ) for i in range(64/8) ])
print keyhex
################### WRITE RESULTS TO A FILE ###########################
keyF = open( "./key.txt", "w" )
keyF.write(keyhex)
keyF.close()
I get the upcoming Error Message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Amine/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "/Users/Amine/anaconda/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
builtins.execfile(filename, *where)
File "/Users/Amine/Downloads/SIKA_Aufgabe_2/ga24feb_timings/framework/main.py", line 13, in <module>
csv_reader = csv.reader(open(timings_csv_file, 'rb'), delimiter=',')
IOError: [Errno 2] No such file or directory: './timings.csv'
I think Python can not find the files in the current directory where it is actually looking for or running since I said: "./file.csv". As far as I know it is looking in its current directory. I know, that if I enter the whole path of the csv-files, it will work, but I want to make it independent of the file-path, thus the code has to be able to work always with the data in its own path.
So how do I have to change the path of Python in order to leave the csv-files where they are and still be able to use "./file.csv". E.g. when I check what path Python is actually looking for by using "sys.path[0]" I get the output " '' " which I do not really understand because what the heck is '' for a path? Moreover, I tried to set my PYTHONPATH but I think the PYTHONPATH only involves data import for modules (is this right?).
So what should I do to set the path Python is looking for such that "./file.csv" works for me.
Thanks!