finding out absolute path to a file from python finding out absolute path to a file from python python python

finding out absolute path to a file from python


Here's how to get the directory of the current file:

import osos.path.abspath(os.path.dirname(__file__))


the answer is to use:

 __file__

which returns a relative path.

os.path.abspath(__file__) 

can be used to get the full path.


The answers so far have correctly pointed you to os.path.abspath, which does exactly the job you requested. However don't forget that os.path.normpath and os.path.realpath can also be very useful in this kind of tasks (to normalize representation, and remove symbolic links, respectively) in many cases (whether your specific use case falls among these "many" is impossible to tell from the scant info we have, of course;-).