How to get an absolute file path in Python

You can use the os.path.abspath() function to get the absolute file path of a file in Python. Here's an example of how you can use it:

import os

file_path = "example.txt"
absolute_path = os.path.abspath(file_path)
print(absolute_path)

Watch a course Python - The Practical Guide

This will give you the absolute path of the file "example.txt" based on the current working directory.