python - Open file in different directory -
i've written function , want open file in subdirectory 'data'.
def _save_exrates(date, rates): """ saves exchange rates data date 'date' in appropriate exchange rates file, described below. """ file = open(os.path.join('data', 'rates-'+date+'.csv'), 'wt') w = csv.writer(file, lineterminator='\n') w.writerow(['code', 'rate']) key, value in sorted(rates.items()): w.writerow([key, value]) file.close()
my program working on windows when run on mac error:
filenotfounderror: [errno 2] no such file or directory: 'data/rates-2001-03-03.csv'
how can open directory on mac windows?
make sure create directory before creating file inside that.
Comments
Post a Comment