python又搞事情 想一統(tǒng)天下?
作者:我的小熊不見(jiàn)了
來(lái)源:SegmentFault 思否社區(qū)
python最近又在搞大事情,就在最近,github上突然多了一個(gè)神奇的項(xiàng)目
git地址:https://github.com/pyscript/pyscript
并且最近一直在更新。一看這個(gè)名字就讓我們不禁想起JavaScript,再去官網(wǎng)一看
pyscript官網(wǎng):https://pyscript.net/
這家伙不僅模仿了JavaScript的名字,甚至連身子都想要取而代之!
官方對(duì)pyscript的期望是可以在瀏覽器上直接運(yùn)行python。
<html>|
...|
<py-script> print('Now you can!') </py-script>|
</html>|
懷著一顆好奇心,我們把github上的代碼克隆下來(lái),發(fā)現(xiàn)是一個(gè)基于node的前端項(xiàng)目,那第一步先把他跑起來(lái)!
進(jìn)入\pyscript-main\pyscriptjs目錄下,
首先安裝依賴(lài) cnpm i 然后先在本地運(yùn)行 npm run dev 打開(kāi) http://localhost:8080/


<body>
Hello world! <br>
This is the current date and time, as computed by Python:
<py-script>
from datetime import datetime
now = datetime.now()
now.strftime("%m/%d/%Y, %H:%M:%S")
</py-script>
</body>

...
<py-script src="/todo.py"> </py-script>
...
<section>
<div class="text-center w-full mb-8">
<h1 class="text-3xl font-bold text-gray-800 uppercase tracking-tight">To Do List</h1>
</div>
<div>
<input id="new-task-content" class="border flex-1 mr-3 border-gray-300 p-2 rounded" type="text">
<button id="new-task-btn" class="p-2 text-white bg-blue-600 border border-blue-600 rounded" type="submit" pys-onClick="add_task">
Add task
</button>
</div>
<py-list id="myList"></py-list>
<div id="list-tasks-container" class="flex flex-col-reverse mt-4">
</div>
<template id="task-template">
<section class="task bg-white my-1">
<label for="flex items-center p-2 ">
<input class="mr-2" type="checkbox" class="task-check">
<p class="m-0 inline"></p>
</label>
</section>
</template>
</section>
def add_task(*ags, **kws):
...
在另一個(gè)todo_pylist.html頁(yè)面中,提供了直接在瀏覽器中運(yùn)行python命令的方法,




評(píng)論
圖片
表情
