动态 __file__

class Tools(object):

    @classmethod
    def _exec_path(self,dir):
        if dir:
            return os.path.dirname(sys._getframe(1).f_code.co_filename)
        else:
            return  sys._getframe(1).f_code.co_filename


tools = Tools()
pwd = partial(tools._exec_path,dir=True)

原文地址:https://www.cnblogs.com/baishoujing/p/9196843.html