But it works with a full file name as well. So D:\rhs\Python\test.py\.. effectively goes up one level from the file, and that's the directory D:\rhs\Python
with open(filename,'w', newline='') as csvfile:
csvwriter=csv.writer(csvfile, lineterminator=os.linesep)
csvwriter.writerow(fields)
csvwriter.writerows(rows)