reconstructing source from objects
Question: I'd like to grab the code from actual python objects. This is the opposite
idea of AST and parse, I have an object in memory and I want to recreate the
source code. I don't want to get down to the byte code that's excessive, I
just want a representation of the code that made the object:

    
    
    In [24]: from django.apps import apps
    In [25]: x= apps.get_app('accounts')
    
    In [26]: x
    Out[26]: <module 'mysite.accounts.models' from '/home/cchilders/work_projects/mysite/mysite/accounts/models.py'>
    
    In [27]: x.
    x.BusinessUnit                       x.models           
    
    In [35]: bizunit = x.BusinessUnit
    
    In [36]: type(bizunit)
    Out[36]: django.db.models.base.ModelBase
    
    import something
    
    bizunit_code = something.something(bizunit)
    

I want the source of all models, but using ast seems too hairy especially
since django provides the `apps` module to grab all models. Now I just need to
untranslate it

Thank you


Answer: You may be able to obtain the source code using:

    
    
    import inspect
    print(inspect.getsource(biz unit))
    

This only works when the argument is a module, class, method, function,
traceback, frame, or code object. If Python is unable to obtain the source
code then this will raise a `IOError`.

