You add a file twice with the file name export.csv, once when you call open() and once when you call numpy.savetxt() . Thus, there are two open files that compete for the same file name. If you pass the file descriptor, and not the file name, to numpy.savetxt() , you will avoid this race condition:
s = ','.join(itertools.chain(dataset)) + '\n' newfile = 'export.csv' f = open(newfile,'w') f.write(s) numpy.savetxt(f, (numpy.transpose(datastack)), delimiter=', ') f.close()
source share