我迫不及待的去試了試。" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營(yíng)銷資訊 > 網(wǎng)站運(yùn)營(yíng) > 你甚至可以用 Python 和 HTML 寫網(wǎng)站了!

你甚至可以用 Python 和 HTML 寫網(wǎng)站了!

時(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)雙向通信。

我迫不及待的去試了試。

讓我們從簡(jiǎn)單的例子開始。首先,在 HTML 文件中添加 py-script 依賴項(xiàng)。




<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>





PyScript 目前處于 一個(gè)早期測(cè)試階段,它還沒有直接用于項(xiàng)目。您可以在GitHub 看到詳情,目前已經(jīng)有8.9k star了。http://github.com/pyscript/pyscript 下面是官網(wǎng)的一些介紹:

PyScript 核心特性

PyScript 目標(biāo)

PyScript 基于 Pyodide 構(gòu)建,Pyodide 由編譯成 WebAssembly 的 CPython 3.8 解釋器組成,允許在網(wǎng)頁瀏覽器中運(yùn)行 Python。Pyodide 可以安裝來自 PyPi 的任何 Python 包。Pyodide 還包括一個(gè)外部函數(shù)接口,可以將 Python 包暴露給 JavaScript,并將瀏覽器 UI,包括 DOM,暴露給 Python。




原文鏈接:



關(guān)鍵詞:

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉