Is it possible to construct human readable source for loaded modules if you have access to sys.modules?
People tell me you cannot, but I’m sure it is possible in Python.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can disassemble a Python-coded module using the dis module of the standard library: that produces definitely human readable source, just not Python source, but rather bytecode source. Putting eggs back together starting from the omelette is a tad harder.
There used to be a decompiler for Python 2.3 (see here) but I don’t know if anybody’s been maintaining it over the last several years, which suggests there isn’t much interest in this task in the open source community. If you disagree, you could fork that project, making your own project with the goal of decompiling 2.7 (or whatever Python release you crave to decompile for), and attract others enthusiastic about this task — if you can find them, that is.