wait, so
a = 257 b = 257
and
a = 257; b = 257
results in different byte code!??
All this time I thought ";" was just a separator. If so, that's some serious code smell coming from the "optimizer".
I personally think PyPy, or something based on LLVM, will end up being the default python in the distant future, with CPython being more of an experimental/latest-and-greatest interpreter. At some point, we're going to start demanding more performance, and it's definitely not going to come from CPython, considering it's many times slower than even javascript (giving brython near CPython performance!).
edit: answer is no, not downvote.
A simpler alternative is to use brython (http://brython.info) which is a Python implementation for the browser written in javascript. You could simply write a static html page with your Python script (and include a link to the brython library). Brython is getting to be fairly mature and works really well.
If I was targeting Python 3, I'd use Transcrypt myself (it looks robust enough compared to the other Python-to-JS shims out there).
I wish I wasn't stuck on 2.7 due to using 2.7 at work (and no, I don't want to juggle two Python versions because that'll end badly for my job efficiency, trying to use some 3.x idiom and failing...) :(
​
EDIT: I'd also look up Evennia, it's a JS/Python MUD engine. But for a portfolio thingy, I'd just go with rot.js instead.
EDIT EDIT: Another Python 3 web thing: http://brython.info/index.html but there's still the matter of displaying.
At least one other person has suggested Brython, but you seemed to have dismissed it off-hand. May I suggest you go to http://brython.info/tests/editor.html and try running any code you might want to have your users running as a test? It's entirely client side, so that, once the page is loaded, your user would see results much faster than if they have to be communicated back and forth between their computer and your server.
Skulpt is limited to Python 2.x; Brython is 3.x based. I use Brython and am quite happy with the results.
You can do it server-side by installing a web framework like Flask or Bottle, as suggested already. But now you can also do it client-side with Brython, without anything to install :
<html> <head> <meta charset="utf-8"> <script type="text/javascript" src="https://cdn.rawgit.com/brython-dev/brython/3.2.2/www/src/brython.js"> </script> </head>
<body onload="brython()">
<script type="text/python"> from browser import document, alert
def GetReverse(ev): word = document['word'].value new_text='' length=len(word)-1
while length>=0: new_text=new_text+word[length] length=length-1
# pop up result alert(new_text)
# document['reverse'] refers to the element with id 'reverse' # bind() tells the browser which function to call when user clicks the button document['reverse'].bind('click', GetReverse) </script>
<input id="word"> <button id="reverse">Reverse</button>
</body> </html>
Python can be used server-side to process HTTP requests, or you can use Brython to simulate python in a browser. I've never seen a python web tool which uses <% %> tags, but that doesn't mean one doesn't exist.
From http://brython.info/doc/en/static_index.html?page=faq: But (Brython) also aims at covering 100% of Python syntax, which includes producing the same error messages as CPython, even if this leads to a slower Javascript. This is a statement that discuss a comparison between Brython and PyJs.
Brython aims to be completely compatible with CPython 3.x; it is actively developed. Skulpt aims for compatibility with CPython 2.x
Did you know that there’s a JS python interpreter that has the same performance as cPython? That’s how shit it is.
They’ll care about speed eventually, they always do.
OK, now I have the confirmation that Brython is OK.
I think all scripts defined on the page will run.
Please read this: http://brython.info/static_doc/en/options.html
>ipy_id : by default, the function brython() runs all the scripts in the page.
Have you tried just copying the first example in the gallery?
http://brython.info/gallery/hello.html
When running on browser, check console (press F12 key on keyboard) to see any errors.
You have to check all needed files and paths on HTML.
Browser-based and Python is a hard combination to get working. There are frameworks like Brython that allow you to run Python code in the browser, but you are effectively running JS that Brython is generating for you. In practice most people simply use Javascript for a browser-based game, optionally with a game framework like gdevelop.
If you're interested in having all the python/js logic on the web page look into Brython.
It can call javascript functions directly. Like that you can keep page logic separated from server logic while still using Python.
I'd suggest Brython. ( http://brython.info/index.html )
It's pretty full-featured, but the docs are, uhhhh, "limited". (By "limited" I mean that out of a full site of content, there are very few complete examples. Most of the code examples are just the python, which doesn't work without the supporting html.)
You can do this very easily with Brython.
Here is an example taken from the page you mention, written without any Javascript ;-)
<HTML> <HEAD> <META charset="utf-8"> <SCRIPT src="/src/brython.js"></SCRIPT> <SCRIPT src="/src/brython_stdlib.js"></SCRIPT> </HEAD> <BODY bgcolor="#FFE4C8" onload="brython(1)">
<H1>Relativity Factor</H1>
<SCRIPT type ="text/python"> import math from browser import document
@document["v"].bind("change") def gcal(ev): # get the first element with tag "form" in the document fh = document.select("form")[0] vv = float(fh.v.value) fh.v2.value = vv gg = 1 / math.sqrt(1 - vv * vv) fh.gam.value = gg </SCRIPT>
<FORM method="" action=""> For v = <INPUT Type="text" Name="v" id="v" Value="" Size="6" autocomplete="off">c <p>β = <INPUT Type="text" Name="v2" Value="" Size="6"> and γ = <INPUT Type="text" Name="gam" Value="" Size="6">.</p> </FORM> </BODY> </HTML>
All you have to do is to edit the path to scripts brython.js and brython_stdlib.js.
You can find other examples on the demo page
Another option is to use Brython to develop the application in a browser, and embed it in an Android application.
Since I'm not too familiar with JavaScript (and honestly I hate it), I'm trying to implement some ajax features to my WebPoster for Telegram using Brython which translates Python code to JS.
Python. Started with Python 2, switched to 3 last year (love it), and now I'm using Brython to support the growing legions of chromebook users.
Python is my favorite, though I came to it only in the past ten years, while becoming a teacher. Before that I was an engineer who used C/C++ exclusively. But really, I love them all. Except Java.
Haven't come back to it yet! After a lot of Googling today I discovered Brython. It's Python that compiles directly to JavaScript to run in a broswer. It basically lets you write more or less pure Python and have your browser act as a GUI. Absolutly nothing need be installed, just add
<script src="http://brython.info/src/brython_dist.js"></scrpt>
in to your HTML header. No server needed whatsoever. It sucks at a lot of stuff but it suits me just fine because I need to do ths without installing any additional software on workplace machines.
Thanks for the tip though. Nothing like real time answers to problems.
If you go to http://brython.info/tests/editor.html, enter the following code:
x = input("test") print(x)
and click "run", a javascript prompt (like a popup) should appear. It works here using Google Chrome. It might not work if you use an old version of Internet Explorer...
Thanks :)
The slowness seems to be to Brython, which I chose to use in order to write the site completely in Python, so that many people could comfortably inspect its source.. Not sure what I can do to fix this problem other than reimplement it in Javascript.. :/
If you change your mind, you could program Python graphic games in browser with:
You could write python code and get javascript code:
brython (real-time): http://brython.info
rapydscript: http://www.pyjeon.com/rapydscript
pythonjs: https://github.com/PythonJS/PythonJS
Without a web server, you also have the option to use Python implementations that run in the browser. Brython supports Python 3 and has a built-in interface with the DOM and modules to generate and manipulate HTML tags and CSS in Python instead of Javascript
They have a fairly complete website (http://brython.info/ with docs in English, French, Spanish and Portuguese), and a very responsive discussion group. Other than a specialize package (browser) designed to deal specifically with the DOM (with a syntax much simpler than Javascript), it's just plain Python 3.
You can use Brython (http://brython.info) to run Python in a browser. I use it to translate Python code (client side) so that it is run in a browser in an application that has user programming a virtual robot. See http://reeborg.ca/world.html for the robot world; you can go to the home page to find a link to a tutorial.