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