Reputation: 303
My script creates a new csv file based on the date. It default saves the file the the local directory. Any idea how i can save it to a specific folder? Thx
with open('record ' + str(current) + '.csv', 'a', newline='') as f:
Upvotes: 0
Views: 426
Reputation: 1
the file parameter in the open function is the path to such file. By indicating only the filename it's assumed as a file on the actual directory, so for writing it anywhere on your drive (as long as you have permissions) you should use full path
with open('/tmp/record ' + str(current) + '.csv', 'a', newline='') as f:
Upvotes: 0
Reputation: 21275
The simplest way would be to add to the open
functions path argument like so:
with open(folder_path + '/' + 'record ' + str(current) + '.csv', 'a', newline='') as f:
Assuming that folder_path
holds a path to the specified folder like '/home/users/you/somefolder'
But I would suggest looking into using PathLib
for path creation & manipulation
Upvotes: 1