跳到內容

Python 程式碼

Python 透過 Pyodide 執行 — 也就是編譯成 WebAssembly 的 CPython — 並跑在一條 獨立的執行緒上。您的機器上不需要任何 Python。

符號用途
input從輸入連接埠收到的值
vars一個裝著執行變數的字典
print(...)寫入執行記錄
最後一個運算式它的值會走 result 連接埠送出
commandes = input["commandes"]
payees = [c for c in commandes if c["statut"] == "payee"]
total = sum(c["montant"] for c in payees)
print(f"{len(payees)} commandes payées, total {total} €")
{"nombre": len(payees), "total": total}

CPython 的標準函式庫都可以使用:jsonredatetimehashlibbase64itertoolscollections……

import hashlib, hmac
signature = hmac.new(
vars["secret"].encode(),
input["corps"].encode(),
hashlib.sha256,
).hexdigest()
{"signature": signature}

請在方塊的 packages 欄位中宣告它們。它們會在第一次執行時從 PyPI 下載、快取 起來,之後便以離線方式載入。

逾時(timeout)或停止執行時,會以一個 KeyboardInterrupt 中斷執行,必要時 再把該執行緒結束掉。