時(shí)間:2023-07-16 16:18:02 | 來源:網(wǎng)站運(yùn)營(yíng)
時(shí)間:2023-07-16 16:18:02 來源:網(wǎng)站運(yùn)營(yíng)
你甚至可以用 Python 和 HTML 寫網(wǎng)站了?。航?,在PyCon US 2022上,Python開發(fā)商Anaconda發(fā)布了PyScript,該框架允許開發(fā)者在HTML中嵌入編寫Python代碼,從而使Python代碼與JavaScript實(shí)現(xiàn)雙向通信。<head><link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /><script defer src="https://pyscript.net/alpha/pyscript.js"></script></head>
當(dāng)然,你不需要安裝Python環(huán)境,也可以直接運(yùn)行,哪怕是直接在桌面新建一個(gè)txt,然后更改后綴名為html即可。示例1:打印 Hello, Friends 和1+1(第一次運(yùn)行會(huì)比較慢,因?yàn)橐螺d依賴,預(yù)計(jì)半分鐘)<html><head><link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /><script defer src="https://pyscript.net/alpha/pyscript.js"></script></head><body><py-script> print('Hello, Friends!') </py-script><py-script> print( 1 + 1 ) </py-script></body></html>
<py-script>:
PyScript 的主要元素。在這里,您可以添加在網(wǎng)頁中可執(zhí)行的 Python 代碼。元素本身不會(huì)呈現(xiàn)到頁面。然后我們接下來用網(wǎng)頁添加一個(gè)Python編輯器。<py-repl>:
這是一個(gè)可用于交互式運(yùn)行 python 代碼的 REPL。Python repl示例:<html><head><link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /><script defer src="https://pyscript.net/alpha/pyscript.js"></script></head><body><py-repl id="my-repl" auto-generate="true"> </py-repl></body></html>
示例3:還可以直接在網(wǎng)頁上進(jìn)行繪圖<html><head><link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /><script defer src="https://pyscript.net/alpha/pyscript.js"></script><py-env> - numpy - matplotlib</py-env></head><body><h1>Let's plot random numbers</h1><div id="plot"></div><py-script output="plot">import matplotlib.pyplot as pltimport numpy as npx = np.random.randn(1000)y = np.random.randn(1000)fig, ax = plt.subplots()ax.scatter(x, y)fig</py-script></body></html>
關(guān)鍵詞:
客戶&案例
營(yíng)銷資訊
關(guān)于我們
客戶&案例
營(yíng)銷資訊
關(guān)于我們
微信公眾號(hào)
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。