TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Introducing PyScript (summary of PyCon keynote)

402 点作者 benhoyt将近 3 年前

36 条评论

travisgriggs将近 3 年前
Ya know, it’s funny. I like Python. We like it enough to actually use it in embedded products. It has its limits, and we use other tools where it doesn’t fit. Python in a browser seems like a keen idea.<p>But JavaScript vs Python isn’t really the key thing for me on the web. It’s the uncanny pile of other software one uses to build a man-machine connection that flummoxes me. It’s the CSS, the DOM, the events, the browser API, the ever churning massive pile of complexity that interactive software has become with the voluminous W3C specs, expressed in near BNF form and full of edge cases and backwards compatibility, all so every thing my user does can be observed by myself a few megacorps. I honestly wouldn’t care if I could write it in Fortran. It’s such a minor wart of the whole mess.<p>Caring about which actual language you can use in all the script tags of a jacked up text format feels like caring which font is being used in your favorite hot piece of government legislation.
评论 #31846274 未加载
评论 #31867452 未加载
评论 #31851311 未加载
评论 #31848041 未加载
codedokode将近 3 年前
The article describes what is possible with Python in a browser, but misses an important detail: how much memory it consumes and how much CPU it uses.<p>Python is not a fast language. For example, consider a simple loop:<p><pre><code> for i in range(10): pass </code></pre> In Python, this will be compiled into: a call to range(), heap allocation of an Iterable, calling getIterator() on an Iterable (which might also do allocation), calling next() on an Iterator while catching for StopIteration exception (and calls are often slow in interpreted languages). While in C we could just have a loop without any calls.<p>I remember how I had to use a Dart-based web application (compiled to JS) in one of Google&#x27;s advertising products. The script weighed around several megabytes and everything was so slow. Furthermore, there also was a small and useless &quot;what&#x27;s new&quot; applet, and it probably was shipped with a separate copy of Dart runtime because it weighed several megabytes too. Obviously this was a product intended to be used only on latest MacBooks, not on a Windows XP laptop.<p>It is totally fine to write such application for youself, or maybe for internal use, but if you are a corporation with millions of users, I think you should pay a little attention to performance and choose a better technology. Or, if you are of a Google scale, find a way to optimize the code.
评论 #31846166 未加载
评论 #31847307 未加载
评论 #31846090 未加载
评论 #31845761 未加载
评论 #31845833 未加载
评论 #31845917 未加载
评论 #31846251 未加载
semiquaver将近 3 年前
<p><pre><code> &gt; But there is another aspect of the language that makes it so desirable from his standpoint: it can be extended with binary extensions that use an API that is written in C, but can be accessed from other languages. He likens Python to &quot;a Honda Civic with mounting bolts for a warp drive&quot;. So the language can be picked up by kids who can then pop open the trunk &quot;and bolt on warp nacelles&quot; that allows the code to run faster than C or C++ in some cases, Wang said. &gt; &gt; That aspect is sometimes overlooked, but it means that Python can be used in ways that other, similar languages cannot. &quot;It&#x27;s not just like Node, it&#x27;s not just an alternative to Ruby&quot;. </code></pre> Both node and Ruby have a comprehensive C API, this is a very common language feature since binding to native libraries is unavoidable. Is there actually anything different about python here?<p><a href="https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;n-api.html" rel="nofollow">https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;n-api.html</a> <a href="https:&#x2F;&#x2F;silverhammermba.github.io&#x2F;emberb&#x2F;c&#x2F;" rel="nofollow">https:&#x2F;&#x2F;silverhammermba.github.io&#x2F;emberb&#x2F;c&#x2F;</a>
评论 #31845251 未加载
评论 #31845080 未加载
评论 #31845485 未加载
评论 #31847629 未加载
评论 #31845156 未加载
评论 #31845054 未加载
79a6ed87将近 3 年前
I would love to see Python in browsers more than Javascript. But since this works through WASM, I&#x27;d probably stick with Rust in that case.<p>If I&#x27;m going to be bound by the limitations of how immature WebAssembly is right now, I&#x27;d at least use its more mature ecosystem for development, which is Rust. And actually, I recently began doing so in my free time with a framework named Yew[1].<p>I know that it&#x27;s unrealistic to expect Python to be a first-class citizen in browsers as JS is, but at some point we&#x27;ll grow tired of reading &quot;X language is now available for browsers&quot; when it&#x27;s more like &quot;X can do WASM now&quot;.<p>edit: Anyway, I don&#x27;t want to come off as under-appreciative of PyScript. I&#x27;m sure a lot of people will love it and make it grow a lot. I&#x27;d probably give it a try someday too. Props to the developers!<p>1 : <a href="https:&#x2F;&#x2F;github.com&#x2F;yewstack&#x2F;yew" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;yewstack&#x2F;yew</a>
评论 #31844635 未加载
评论 #31844974 未加载
dragonwriter将近 3 年前
PyScript seems interesting, but must we have infomercial-level hyperbole at the adversity of the status quo to sell it?<p>&gt; For example, you cannot write iOS apps with Python. You cannot create an application for Windows—the most popular corporate desktop—with a user interface<p>You can, in fact, do both of those things with Python. Heck, the latter you can do with the standard library alone.
评论 #31844957 未加载
评论 #31845491 未加载
评论 #31844889 未加载
nmstoker将近 3 年前
I&#x27;m really enthusiastic about what&#x27;s happening with PyScript as the opportunities for the right use cases are enormous.<p>That said, it has really brought out the knee-jerked clichéd responses:<p>- X is way better than Y<p>- X is the Y killer &#x2F; no it isn&#x27;t<p>- Did you know Python is really slow?<p>- Sure you can, but why do this? (implication: don&#x27;t do this)<p>To add to the fun, it attracts huge interest, and amongst those interested are a weird set of people who seem to know little about Python, little about JavaScript and seem unable to read before they try something impossible and then post a query about why their almost certainly never-going-to-work attempt hasn&#x27;t worked! It needs plenty of patience pointing them to the huge pile of matching queries! I&#x27;m sure something will be done to give those types a friendly nudge in the right direction.
评论 #31850295 未加载
bluedays将近 3 年前
I use to want this. Then I learned JavaScript, and decided it&#x27;s a much better language for the browser than Python is.
评论 #31844600 未加载
评论 #31845638 未加载
评论 #31845209 未加载
asojfdowgh将近 3 年前
Hello World example:<p>15 requests. 21.65 MB &#x2F; 7.66 MB transferred. Finish: 8.19 s. DOMContentLoaded: 707 ms. load: 2.95 s.<p>no, stop. I&#x27;m super confused about the obsession of clonking specifically the reference implementation when other implementations exist, like micropython for example. Sure, less compatible, but you are already not getting native modules so shrug?
评论 #31845841 未加载
评论 #31845845 未加载
评论 #31845963 未加载
评论 #31847798 未加载
benatkin将近 3 年前
This is also sandboxed FWIW. It means users could write plugins in Python and have them run securely, much like browsers running JavaScript, and games that have Lua scripting.<p><a href="https:&#x2F;&#x2F;webassembly.org&#x2F;docs&#x2F;security&#x2F;" rel="nofollow">https:&#x2F;&#x2F;webassembly.org&#x2F;docs&#x2F;security&#x2F;</a> <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;WebAssembly&#x2F;comments&#x2F;ryz2zz&#x2F;are_wasm_binaries_still_vulnerable_from_memory&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;WebAssembly&#x2F;comments&#x2F;ryz2zz&#x2F;are_was...</a><p>Deno also touts its permission system. It will be interesting to see if both get interesting use.<p>micropip is impressive. A lot of JavaScript dev still depends heavily on Node, to the point that only one browser-based build tool exists that can handle most projects and they&#x27;re keeping it proprietary: <a href="https:&#x2F;&#x2F;blog.stackblitz.com&#x2F;posts&#x2F;introducing-webcontainers&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.stackblitz.com&#x2F;posts&#x2F;introducing-webcontainers&#x2F;</a>
stavros将近 3 年前
This is a laudable effort, but I&#x27;m not a fan of shipping the entire interpreter. I looked around a few weeks ago and found <a href="https:&#x2F;&#x2F;transcrypt.org" rel="nofollow">https:&#x2F;&#x2F;transcrypt.org</a>, which compiles your Python script to JS, so size is minimal.<p>It&#x27;s great for shipping small, internal tools&#x2F;apps, I love how maintainable they are by all the Python devs, plus they&#x27;re very fast to load and execute.
评论 #31844695 未加载
评论 #31844660 未加载
评论 #31845097 未加载
评论 #31845250 未加载
评论 #31845027 未加载
Cadwhisker将近 3 年前
The video of this presentation is here: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;qKfkCY7cmBQ" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;qKfkCY7cmBQ</a>
eddyg将近 3 年前
How does this compare to Brython? [0]<p>Brython uses:<p><pre><code> &lt;script type=&quot;text&#x2F;python&quot;&gt; </code></pre> [0] <a href="https:&#x2F;&#x2F;brython.info&#x2F;" rel="nofollow">https:&#x2F;&#x2F;brython.info&#x2F;</a>
评论 #31845056 未加载
评论 #31846365 未加载
benhoyt将近 3 年前
While I love the tech behind this (as well as the good article and fun demo video), I&#x27;m very skeptical that this will be a good approach for most web apps. I hope it doesn&#x27;t turn into Python programmers suddenly pulling in 7MB of WASM code&#x2F;data just to render their websites (along with a 5s startup time), adding yet another layer of complexity and virtualization between their code and the browser. I think the interest in the tool is overall a good thing, but I think we need to be very careful about what kinds of projects we use this for.
评论 #31844798 未加载
评论 #31844694 未加载
评论 #31844781 未加载
评论 #31847218 未加载
评论 #31844670 未加载
pjmlp将近 3 年前
What is new is old again.<p>ActivePython was available via the &lt;object &#x2F;&gt; tag for Internet Explorer back in the early 2000&#x27;s.<p><a href="https:&#x2F;&#x2F;www.componentsource.com&#x2F;product&#x2F;activepython&#x2F;about" rel="nofollow">https:&#x2F;&#x2F;www.componentsource.com&#x2F;product&#x2F;activepython&#x2F;about</a>
评论 #31847195 未加载
bb88将近 3 年前
I was looking at PyScript and I was disappointed when I saw this code.<p><a href="https:&#x2F;&#x2F;pyscript.net&#x2F;examples&#x2F;d3.html" rel="nofollow">https:&#x2F;&#x2F;pyscript.net&#x2F;examples&#x2F;d3.html</a><p>The python version is much much slower loading at least on my browser. I counted 7 seconds to having it render the graph.<p>I kinda wish they spent the time thinking about Dom manipulation from a pythonic point of view rather than just providing the python to js interface and calling it a day.
评论 #31844528 未加载
评论 #31845341 未加载
评论 #31844805 未加载
fny将近 3 年前
Does anyone else remember the Java &lt;applet &#x2F;&gt; days? It seems like we&#x27;ve come full circle after twenty years.
评论 #31845804 未加载
评论 #31845199 未加载
评论 #31844746 未加载
abidlabs将近 3 年前
An alternative, which doesn&#x27;t require insane loading times, is to use any of the many great Python libraries that allow you to write web apps in Python, which get converted to JS web apps.<p>For example, I&#x27;m one of developers of Gradio [0], which lets you write your web app in Python, which gets rendered using Svelte-based components:<p>[0] <a href="https:&#x2F;&#x2F;www.gradio.dev" rel="nofollow">https:&#x2F;&#x2F;www.gradio.dev</a>
评论 #31844880 未加载
评论 #31844540 未加载
评论 #31844607 未加载
skybrian将近 3 年前
They say that Python has good bindings to C extensions, but for C libraries compiled to WebAssembly, someone will probably write some nice JavaScript bindings, so you might as well use JavaScript.<p>Meanwhile, JavaScript has been extended with so many language features that it&#x27;s hard to see another scripting language giving people good reasons to switch. In the early days, JavaScript programming was very limiting and alternatives had a chance, but those days are pretty much over and I&#x27;d recommend just learning JavaScript.<p>(I say this as someone who spent more time exploring alternative languages than writing JavaScript by hand. Nowadays it&#x27;s hard to come up with a good reason to bother.)
lo5将近 3 年前
Related, I work on Nitro[1], which already offers a polished set of widgets, and a very simple way to author web apps using Python. I&#x27;ll be releasing Pyodide support this week.<p>I also contribute to Wave[2], which provides a wide variety of widgets that can be snapped together quickly to build realtime dashboards&#x2F;apps.<p>Both help non-front-end folks build web apps, and require no knowledge of HTML&#x2F;JS&#x2F;CSS.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;h2oai&#x2F;nitro" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;h2oai&#x2F;nitro</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;h2oai&#x2F;wave" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;h2oai&#x2F;wave</a>
wly_cdgr将近 3 年前
Article reports the guy as saying you can&#x27;t use Python to do a GUI Windows app. Actually there are lots of ways to do this -<p>* Panda3D&#x27;s main language is Python<p>* Godot has Python bindings<p>* So does raylib<p>...
评论 #31845234 未加载
d--b将近 3 年前
No, this is not a project to replace javascript in the browser, this is a project to give Python apps an html-rendered frontend. And yes, you should expect this to be packaged in electron apps.<p>Maybe it is sad, but it’s definitely the shortest path to brining modern frontend dev to Python.
javierluraschi将近 3 年前
At <a href="https:&#x2F;&#x2F;hal9.com" rel="nofollow">https:&#x2F;&#x2F;hal9.com</a>, we built components for data science in native JavaScript to avoid the waiting times and download overhead if Pyodide. We found out the best tools for doing data science in the browser are a combination of Arquero and D3 and TensorFlow.js. At least for now.<p>We wrote our findings of this and many other libraries here: <a href="https:&#x2F;&#x2F;news.hal9.com&#x2F;posts&#x2F;data-science-with-javascript" rel="nofollow">https:&#x2F;&#x2F;news.hal9.com&#x2F;posts&#x2F;data-science-with-javascript</a>
评论 #31844899 未加载
asiachick将近 3 年前
From like 2003 to 2010 I loved Python. I was happy to code in it. Found it much better than Perl, my previous no-manual-compile-link-step language. I was mostly a C++ developer but wrote several large tools in python.<p>I slowly started making more JavaScript stuff and used Selenium (python IIRC).<p>Then I started learning node. Liked npm&#x27;s default to local project installs vs python&#x27;s default to system installs. Eventually I started writing the command line tools that I&#x27;d have written in python previously in node. node had some sync I&#x2F;O so it wasn&#x27;t hard. Then promise&#x2F;async&#x2F;await arrived and I was fully in. I haven&#x27;t written much python in probably 9 years now.<p>When I do look at python, I don&#x27;t feel it&#x27;s better. I&#x27;m not saying it&#x27;s worse nor am I saying it&#x27;s not better, rather I&#x27;m saying it doesn&#x27;t *feel* better. Basically I&#x27;ve learned JS inside and out and I&#x27;m super comfortable there.<p>I find it easier to get node installed on multiple platforms and installing it locally without root&#x2F;admin privileges is trivial via nvm. I&#x27;m sure that&#x27;s possible with python but it&#x27;s certainly not the default. And of course the browser is everywhere so it&#x27;s just way more accessible&#x2F;sharable in JS
zinclozenge将近 3 年前
I&#x27;m using the underlying project, Pyodide, to launch a worker that can execute code and provide autocompletions (via jedi) to a codemirror editor. I&#x27;m not super crazy about the startup times, but I&#x27;m hoping that there will be more work to help optimize it further.
chrischen将近 3 年前
I don&#x27;t see much point in going from one dynamic untyped language to another. Javascript and Python offer much of the same advantages and disadvantages, but having to deal with the overhead of running python code seems to just saddle it with tradeoffs for no real benefit. Learning one or the other is fairly easy too.<p>May as well write Javascript directly, as NPM is not short on packages if that&#x27;s what you need. I see more value in going from higher level languages like ReScript, Purescript, Melange (Reasonml + Rescript compiler) to Javascript. You have to deal with things like code interop, strictness, overhead of compilation, but you at least gain in safety and succinctness.
评论 #31844778 未加载
评论 #31844765 未加载
tehsauce将近 3 年前
My first impressions using pyscript:<p><a href="https:&#x2F;&#x2F;pwhiddy.github.io&#x2F;more-writing&#x2F;2022&#x2F;05&#x2F;05&#x2F;Pyscript-Test.html" rel="nofollow">https:&#x2F;&#x2F;pwhiddy.github.io&#x2F;more-writing&#x2F;2022&#x2F;05&#x2F;05&#x2F;Pyscript-T...</a>
评论 #31844909 未加载
jenny91将近 3 年前
I just love LWN for how impartial and informative it is. It&#x27;s a bit clunky with 20x&quot;he said&quot;, but it sure does a good job of giving me a balanced idea of what this is all about! Happy to be a subscriber.
nine_k将近 3 年前
Wow. The article means using <i>pandas</i> in the in-browser demo.<p>How do they do it? The whole point of numpy and pandas stuff is that they are Fortran and C code that does numeric operations very quickly, while the Python part gives a nice and ergonomic interface on top of them.<p>So they are showing a WASM port of NumPy &#x2F; Pandas now, with the Python interface finally surfacing in the browser. It should be a very fair bit slower than native code, though.<p>Are we seeing the Atwood Law stumbling? That is, things are still migrating into the browser, but to WASM instead of JS now?
notpushkin将近 3 年前
What I really hate about this is the absolutely disastrous API. From the &lt;py-script&gt; tag that could easily have been more standard-ish &lt;script type=&quot;text&#x2F;python&quot;&gt;, to &lt;py-config&gt; and &lt;py-env&gt; that embed YAML for some reason, to weird custom components like &lt;py-inputbox&gt; that don&#x27;t integrate with existing ecosystem at all. Brython, albeit still clunky, got it a lot better.<p>[Brython]: <a href="https:&#x2F;&#x2F;www.brython.info&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.brython.info&#x2F;</a>
smitty1e将近 3 年前
Does WASM end up succeeding generally where Parrot[1] seems to have done otherwise? Right now WASM is browser-bound, but that did not stop Node.<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Parrot_virtual_machine" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Parrot_virtual_machine</a>
评论 #31844699 未加载
tpoacher将近 3 年前
Will PyScript honour the same naming tradition as JavaScript (which has nothing to do with Java) and thus have nothing to do with Python?
blauditore将近 3 年前
Isn&#x27;t this the same idea as GWT (which is Java in the browser)? That one turned out to be impractical, e.g. for debugging.
encryptluks2将近 3 年前
Browsers definitely need an alternative to JavaScript but this doesn&#x27;t look like the native integration I was hoping for.
make3将近 3 年前
let&#x27;s be real, this has no chance of seeing any real adoption, except as a novelty or for technical demos, because the runtime takes multiple seconds to download, which is insane. reading that document without anything addressing this felt like I was taking crazy pills
fbanon将近 3 年前
Nice! Fans of the two most awful languages fighting each other. I&#x27;m just gonna grab some popcorn!
评论 #31848093 未加载
wly_cdgr将近 3 年前
I really, REALLY hate the idea of fracturing the frontend ecosystem further with another scripting language option when there is already an absolutely insane overabundance of tools and frameworks for JS alone<p>It should at this point be enshrined as an official binding standard that browser UAs must support JS and must NOT support any other scripting languages
评论 #31845291 未加载
评论 #31845158 未加载