Last active
May 9, 2026 22:00
-
-
Save rgov/80ef30458a33815d9dd97d7fb6289d89 to your computer and use it in GitHub Desktop.
A Python/YAML polyglot quine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3.6 | |
| line1: str = r'def foo():' | |
| line2: str = r' print("hello world")' | |
| line3: str = r'foo()' | |
| _run: NoneType = exec('\n'.join(v for k, v in locals().items() if k.startswith('line'))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a: 0=exec(s:='import yaml;print(yaml.dump({"a":f"0=exec(s:={s!r})"})[:-1])') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| line1: str = r'''import yaml''' | |
| line2: str = r'''src = "\n".join(f"line{i+1}{chr(58)} str = r\'''{l}\'''" for i, l in enumerate(v for k, v in locals().items() if k.startswith('line')))''' | |
| line3: str = r'''src += f"\n_code{chr(58)} str = '\\n'.join(v for k, v in locals().items() if k.startswith('line'))"''' | |
| line4: str = r'''src += f"\n_run{chr(58)} NoneType = exec(_code)"''' | |
| line5: str = r'''print("#!/usr/bin/env python")''' | |
| line6: str = r'''[ print(f"{k}{chr(58)} {v}") for k, v in yaml.safe_load(src).items() ]''' | |
| _code: str = '\n'.join(v for k, v in locals().items() if k.startswith('line')) | |
| _run: NoneType = exec(_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment