How do I get the path and name of the file that is currently executing?

__file__

as others have said. You may also want to use os.path.realpath to eliminate symlinks:

import os

os.path.realpath(__file__)

Leave a Comment