Skip to content

Comment on Polycompiler: Merge Python and JavaScript code into one file that runs in both

Comments

I'll raise you a polyglot script that doesn't require eval: :)

  1 // len("""
  console.log('javascript');
  /* """)
  print('python');
  # */
Example:
  # python3 /tmp/test.py
  python
  # node /tmp/test.js
  javascript
I _believe_ the only source limitations are the the JS cannot contain `"""` and Python cannot contain `*/`.

use r"" (raw-string literals), to avoid breaking on invalid Python escape sequences in the javascript part.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.