1

I am new here, so sorry for any mistakes. I am using spyder 3.0.0 and iPython console.

I have mistakenly overwritten my custom module file. My last hope is that I have loaded it in iPython console. Is there any way to get the source code "back" from the console?
The console lists all the names (of my overwritten module) after calling dir (modulename), it also creates objects and hint arguments for objects' methods.
I have tried (after importing inspect) print(inspect.getsource(MyClass)), but it throws

File "C:\Users\witek\Anaconda3\lib\inspect.py", line 613, in getfile
raise TypeError('{!r} is a built-in class'.format(object))

TypeError: <module '__main__'> is a built-in class

If I call print(inspect.getsource(MyModule)) it returns the source code of the file that I saved under my module name.

I will really appreciate any help! :)

7
  • 1
    is this what youre looking for? stackoverflow.com/questions/2055110/… Commented Aug 26, 2018 at 20:35
  • You’re looking for a decompiler that you can apply to the code objects in your surviving session. Commented Aug 26, 2018 at 21:35
  • what if you use inspect.getsource on a function inside the module? Commented Aug 26, 2018 at 21:41
  • 2
    @Stanley thanks, but solutions posted there didn't work for my case (source code file gone) Commented Aug 26, 2018 at 21:43
  • @xdze2 File "C:\Users\witek\Anaconda3\lib\inspect.py", line 804, in findsource if pat.match(lines[lnum]): break IndexError: list index out of range Commented Aug 26, 2018 at 21:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.