0

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:

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.