Settings

Theme

How to Write a Quine

czterycztery.pl

3 points by fourgreen 9 months ago · 1 comment

Reader

bccdee 9 months ago

My favourite way to do it is with `format()`, as in

    a="""a={q}{q}{q}{a}{q}{q}{q}
    b=a.format(q={q}{b}{q}{q}, b={q}{b}{b}{q}, a=a)
    print(b)"""
    b=a.format(q="\"", b="\\", a=a)
    print(b)
You can shorten it further by replacing """ with ", replacing newlines with semicolons, and replacing {q} {b} {a} with {0} {1} {2}. You can do this same design with `printf`, using directives like `$1%s`. It feels more minimal than using `repr` to me, though obviously that's completely subjective.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection