2 ms·
This is actually a valid problem when writing quines[1]. You need to escape string delimiters in a way without using its literal. This is what `chr(39)` is for
by ivanjermakov 2y ago
This is actually a valid problem when writing quines[1]. You need to escape string delimiters in a way without using its literal.
This is what `chr(39)` is for in the following Python quine:
a = 'a = {}{}{}; print(a.format(chr(39), a, chr(39)))'; print(a.format(chr(39), a, chr(39)))
[1]: https://en.wikipedia.org/wiki/Quine_(computing) https://en.wikipedia.org/wiki/Quine_(computing)
- eru 2y agoYou don't need these gymnastics of knowing ASCII in Python quines: a = '''a = {} print(a.format(repr(a)))''' print(a.format(repr(a))) (OK, it's not a quine yet, because the output has slightly different formatting. But the formatting very quickly reaches a fixed point, if you keep feeding it into a Python interpreter.) The actual quine is the slightly less readable: a = 'a = {}\nprint(a.format(repr(a)))' print(a.format(repr(a))) https://github.com/matthiasgoergens/Quine/blob/c53f187a4b4030437005ddd12bd5a8594269b437/quine.c https://github.com/matthiasgoergens/Quine/blob/c53f187a4b403... has a C quine that doesn't rely on ASCII values either.