gilbert189 — 5/30/2023, 12:10:30 PM

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)

♥ 2 ↩ 0 💬 3 comments

comments

radi8:
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
5/30/2023, 12:13:09 PM
gilbert189:

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

5/30/2023, 12:15:21 PM
radi8:
pi@pie:~ $ python3 --version
Python 3.9.2
5/30/2023, 12:17:04 PM