Skip to content

Understanding Your Working Directory When Working With Python

When writing Python code, it’s good to know where your working directory (or current working directory) lives. When you perform file operations without specifying a file path, Python defaults to the working directory, which might be fine….or you might not be able to find your files.

I wrote a blog post about exporting data to Excel with examples of specifying and not specifying the absolute file path so you can see the difference. Click here for that post.

Finding the Working Directory

We can use the os module to find our working directory. This particular module is part of Python’s standard utility modules. For more information on the os module, check out this link.

Changing the Working Directory

If you want to modify the working directory, use this.

And that is what you need to know about your working directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.