ℹ️
×

⚙️ How This Python Runner Works

This tool lets you run Python code in your browser using Pyodide, with extra handling for Python's print, input() and time.sleep() using JavaScript equivalents. In error messages you may see one line numbering excceds by one because behind the scene it adds one line import js, asyncio You can see the parsed code in console if you want!

🧠 Behind the Scenes

  • Automatically replaces:
    • printjs.print
    • inputawait js.input
    • time.sleepawait asyncio.sleep
  • Adds async to def if the function calls an awaitable input() or time.sleep()
  • Wraps matching function calls with await.
  • Functions must be defined above where they are used.

⚠️ Limitations

  • Recursive functions using await may not be detected properly.
  • Functions must be declared above where they are called.
  • Parser does not fully handle nested scopes or multiline strings yet.
  • All parsing is done with regex and string manipulation — not a full AST.
  • Code must follow basic indentation rules to avoid false matches.
  • There is no way to differentiate between strings like "\'" and "'" because both are stored as "'"
  • you can't apply anything like upper() on input() which is a PyodideFuture object so it might show errors like AttributeError: 'PyodideFuture' object has no attribute 'upper'
  • Don't define in the same line as def i.e., don't do this: def f(a,b):return a+b
  • By default all functions are async except for dunders

📌 Tips for Writing Compatible Code

  • If you use quotes inside strings it is better if you use `"back"'ticks'` or use "different 'quotes'" for 'string and "inside quotes"'
  • Write input like normal — async is added automatically.
  • Use time.sleep() instead of sleep() to ensure correct replacement.
  • Avoid defining functions after usage if they call async behavior.
  • If you are using input() to do something like input().upper() do this instead (input()).upper() this will let input() resolve 1st then will apply your functions to the value
  • If you want to define a synchronous function then add an underscore _ at the end for example:transmitError_