Not A Good Quine

(aka. A Quine So Clever It’s Cheating)

# doesn't work in Python 3.9+
import inspect, __main__
print(inspect.getsource(__main__), end="")

(there should be a newline at the end btw)

May 30, 2023, 12:10 PM
2 0 3

comments (single view)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/inspect.py", line 1024, in getsource
    lines, lnum = getsourcelines(object)
  File "/usr/lib/python3.9/inspect.py", line 1006, in getsourcelines
    lines, lnum = findsource(object)
  File "/usr/lib/python3.9/inspect.py", line 817, in findsource
    file = getsourcefile(object)
  File "/usr/lib/python3.9/inspect.py", line 697, in getsourcefile
    filename = getfile(object)
  File "/usr/lib/python3.9/inspect.py", line 660, in getfile
    raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module '__main__' (built-in)> is a built-in module

oh, so that’s a thing in Python 3.9+

pi@pie:~ $ python3 --version
Python 3.9.2
View all comments