Ned Deily added the comment:
In duplicate Issue24491, zorceta notes: "Both python.exe and IDLE can't.
IPython is able to, as it inserts REPL input into linecache."
--
nosy: +ned.deily, zorceta
versions: +Python 3.5, Python 3.6 -Python 3.2, Python 3.3
___
Éric Araujo added the comment:
> It seems to work perfectly on command line though.
If the code is saved in a file, yes, but not in an interactive interpreter.
This is not actually related to IDLE, but to the fact that inspect.getsource
merely finds the __file__ attribute of the module object