V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
woshichuanqilz
V2EX  ›  Python

有人用 pyscript 了吗 我这里测试例没用

  •  
  •   woshichuanqilz · 2022-05-09 00:04:49 +08:00 · 2992 次点击
    这是一个创建于 690 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这个代码 print 打印不出来, firefox 和 chrome 都测了, 这个可能是什么问题?

    <!DOCTYPE html>
    <html>
    
    <head>
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    </head>
    
    <body>
    
        <h1>My First Heading</h1>
        <p>My first paragraph.</p>
        <!-- Magic is here! -->
        <py-script>
            print("hello")
        </py-script>
    </body>
    
    </html>
    
    7 条回复    2022-05-10 21:14:06 +08:00
    ruxuan1306
        1
    ruxuan1306  
       2022-05-09 03:20:05 +08:00
    试了下没问题,注意缩进就可以:
    ![O88DTP.png]( https://s1.ax1x.com/2022/05/09/O88DTP.png)
    l4ever
        2
    l4ever  
       2022-05-09 08:23:08 +08:00
    f12,打开 network 看看
    acehowxx
        3
    acehowxx  
       2022-05-09 08:23:23 +08:00 via Android
    chrome 是可以的。你得等,因为用的是 web assembly 实现的,所以特别慢。你等 2 分钟是会出来结果的。我觉得如果谷歌不在浏览器层面进行优化提供个 py 的 v8 引擎支持的话,以现在这种运行速度,这个项目前景不明。
    silkriver
        4
    silkriver  
       2022-05-09 08:48:54 +08:00
    我刚试了直接双击的话等 40 秒,通过 nginx 的话 5 秒
    Abbeyok
        5
    Abbeyok  
       2022-05-09 09:05:40 +08:00
    前端写 python ,有点鸡肋
    v2defy
        6
    v2defy  
       2022-05-09 10:09:13 +08:00
    我用了你的代码,一个字没改,可以执行,页面上除了那两行”My first...“之外,第三行先是空白,然后闪过 print("hello"),然后迅速变成了 hello ,耗时大约 3 秒左右
    ahalamora1981
        7
    ahalamora1981  
       2022-05-10 21:14:06 +08:00
    ____<py-script>
    print("hello")
    ____</py-script>

    这样写(回复框格式问题,我用下划线 "_" 代表空格)。所有<py-script>标签内的 python 代码不能有缩进,要顶着左边框写。python 严格缩进,HTML 不严格缩进,所以这个问题将来也是很难解决的。我自己就是写一个方法放在 py 文件里,html 只是调用,这样干净一点。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5431 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 08:45 · PVG 16:45 · LAX 01:45 · JFK 04:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.