import os root_path = os.path.abspath(os.path.dirname(__file__)) while not os.path.isfile(os.path.join(root_path, '.gitignore')): root_path = os.path.dirname(root_path)