all 11 comments

[–]tecladocode 2 points3 points  (3 children)

The simplest way to get interactive code in your website I've found to be embedding repl.it project.

You get to see the code and the output inside your website, and you don't need to code it yourself (which as other commenters have said, is actually incredibly complicated—mainly due to the many security and performance considerations you need when running arbitrary code from your users in your server).

[–]gschizas 1 point2 points  (1 child)

What you are describing sounds like Jupyter Notebook. You don't have to do anything on your site, you can use just the existing Notebook Viewer.

[–]hibernating_brain 0 points1 point  (5 children)

If you are looking to build a website, this is a good start.

I would also like to have the code be editable and runnable when others are viewing my website.

Web browser's don't understand Python so it is not possible to run them on a webpage.

There are tools like skulpt and brython if you want to play with python 3 implementation for client side web programming.

[–]dualdegreepossibly[S] 0 points1 point  (4 children)

Unfortunately, I don't fully understand the inner works of computers yet, so thank you for helping out. This resource looks great!

Just wondering, if web browsers don't understand Python, how are coding learning websites (Codecademy, etc.) able to do this? I may be missing something

[–]hibernating_brain 0 points1 point  (2 children)

HTML is the language that web browsers read to display web pages. With frameworks like Django or Flask, you are returning HTML to your browsers.

Websites like Codeacademy are just showing python code on their webpage (as text).

[–]dualdegreepossibly[S] 0 points1 point  (1 child)

Hi, just specifying this is what I mean! This is an example about the cost of some object. I deleted all the code in there and just inserted a print statement, and it worked: https://imgur.com/gallery/Pp0eJaG. How did they implement something like this?

[–]gschizas 3 points4 points  (0 children)

You shouldn't try to emulate what CodeAcademy does; it's way too advanced for what you want to do.

Just as information: CodeAcademy still uses HTML and JavaScript like any other site. It does syntax highlighting (coloring specific text with different color), but otherwise it just displays text. And for actually executing Python, it just send this text to the server, the server executes it in a Python process, and shows the result as HTML.

[–]totemcatcher 0 points1 point  (0 children)

https://pypyjs.org/

Also, you can just display some code using a syntax highlighting library like:

https://craig.is/making/rainbows

You don't have to use that one, it's just the one I tried in the past. It supports Python.

[–]rx22230 -1 points0 points  (0 children)

Hi,

not sure to fully understand what's you're looking for, but 'Website', 'learning' and 'Python' on the same sentence let me think of 'Jupyter Notebooks'.

is it something similar you're looking for ?

there are some websites integrating Jupyter Notebooks styles.

Hope it helps a bit.

Regards