Python Code Generator (pycogen) is a tool to quickly generate python code by dragging blocks together,
and see the python code being built. It is built using Blockly and Highlight.js
Who is pycogen for? pycogen is for people who:
have learnt the basics of programming using a block-based system such as Scratch or other Blockly-based platforms, and who are moving on to learn python;
are already programmers, but are supporting someone learning python;
are just learning python as a first language who want an easy way to try new ideas; or
know some python (or coming from another language) but want a visual/interactive cheatsheet.
How does it work? The left panel on the screen is the canvas for code blocks. The blocks are organised into a menu of functional
types (loops, text, logic etc) from where they can be dragged onto the canvas. When on the canvas, blocks can be
snapped together to build a program. If you have used Scratch or other block coding tools before, this will all feel very familiar.
As the blocks are assembled, the panel on the right will begin to display the Python code that corresponds to the
block program. The Python code will be displayed with syntax highlighting to make it easier to read.
What can I do with the code? Above the Python code panel are buttons that enable you:
to carry out a basic test of the code by running it in the browser;
to export the code to download a .py text file to edit or run elsewhere; and
to copy the code to the clipboard so you can paste it elsewhere.
If you have used the block coding to build some basic code, you will probably want to put that code into a text
editor and make some changes before running it in a fully-functional Python interpreter.
You could have a suitable editor and Python environment set up on your computer for this, where you can load the .py
file downloaded from pycogen, or paste the code copied from your browser.
Alternatively, you might want to continue using online tools to develop and test your code - in this case I would
recommend www.repl.it which can provide a full code editor and Python interpreter online where you can upload a .py file,
or just paste your code copied from pycogen. A link to launch a (no sign up required) Python 3 REPL is included below the
code window. If you choose to sign up for a free account you can also save (and share) your projects.
As you build blocks, your Python code will appear here:
Click here to launch a Python 3 REPL at repl.it in a new window