os.path.splitext(os.path.basename(__file__)) 0 code example Example: python get base directory import os os.path.dirname(os.path.realpath(__file__))