What is the best practice for working with files and paths?

Viewed 4210

I am creating a python script that essentially takes a 'path to a file' as an argument by the user. It does some post processing and creates a new file in the same directory as the original file.

For example: myscript.py C:\\A\\sub_A\\work_on_this_file.csv

I'm using the path I received itself to create a File Handler for
C:\\A\\sub_A\\final_file.csv

I've been told to use os.chdir() to navigate to the folder instead and create my final file there instead of using paths directly. What is the best practice in such a scenario? Is there a risk in not changing the working directory?

2 Answers
Related