Dynamically created method and decorator, got error 'functools.partial' object has no attribute '__module__'

前端 未结 7 766
面向向阳花
面向向阳花 2020-12-31 01:58

I am currently using EndpointsModel to create a RESTful API for all my models on AppEngine. Since it is RESTful, these api have a lot of repeat code which I want to avoid.

7条回答
  •  青春惊慌失措
    2020-12-31 02:39

    In Python 3.5 I have found that a reference to the original function is maintained in the partial. You can access it as .func:

    from functools import partial
    
    def a(b):
        print(b)
    
    
    In[20]:  c=partial(a,5)
    
    In[21]:  c.func.__module__
    Out[21]: '__main__'
    
    In[22]:  c.func.__name__
    Out[22]: 'a'
    

提交回复
热议问题