I've written a function and I want to open a file in a subdirectory 'data'.
def _save_exrates(date, rates): """ Saves the exchange rates data for date 'date' in the appropriate exchange rates file, as described below. """ file = open(os.path.join('data', 'rates-'+date+'.csv'), 'wt') w = csv.writer(file, lineterminator='\n') w.writerow(['Code', 'Rate']) for key, value in sorted(rates.items()): w.writerow([key, value]) file.close()
My program was working on Windows but when I run it on Mac I get the error:
FileNotFoundError: [Errno 2] No such file or directory: 'data/rates-2001-03-03.csv'
How can I open the directory on Mac as well as Windows?