Best Practice to Get the Absolute Path of Current Python Script – Python Tutorial

By | August 26, 2019

In this tutorial, we will introduce how to get the absolute path of current python script, it is very useful for you when you are operating files. You can get pathes of other files based on it.

Import library

import os

Get the absolute path of current python script

absolute_path = os.getcwd()
 
print('your script is located at "' + absolute_path + '"')

The absolute path is:

your script is located at "E:\workspace-nlp\Example"

Then if you want to get directory, file name and file extension, you can read this tutorial.

Python Get Directory, File Name and Extension from an Absolute Path – Python Tutorial

 

Leave a Reply

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