14: Reading data from a file in python

Being able to read and process data from a file is a very useful skill that can save hours of time by allowing you to automate repetitive tasks very quickly.

Use and store data in files
Reading data from a file in python

Contents:

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.

Continue Reading14: Reading data from a file in python

13: Writing data to a file in python

The power of python for processing data becomes even more useful when you can save the output from your program to a file.

Use and store data in files
Writing data to a file in python

Contents:

Page 1: Intro

Page 2: The theory: learn what you need to know as fast as possible.

Page 3: Try it: try out and adapt some working python code snippets.

Page 4: Debug it: Learn how to find and fix common mistakes.

Page 5: Extend it: Choose a project idea to use your newfound python skills.

Continue Reading13: Writing data to a file in python

Using create.withcode.uk to embed python code in an external website

Create.withcode.uk lets you write, run, debug and share python code in your browser. It’s designed for use in the classroom as a free online resource for teachers to help students grow in confidence, independence and resilience when writing python code.

Create.withcode.uk uses a subset of the python language which runs in your web browser. This allows you to safely run python code on almost any web-enabled device.

This is guide is for developers who have an educational tool which contains / generates python code, who want to allow users to view / edit / run that code with all the features that create.withcode.uk supports (e.g. microbit / pygame zero / gpiozero / tkinter emulation).

If you’re just looking to embed code that you’ve written in create.withcode.uk you don’t need this facility: just save your code (or Ctrl + S) and press the share button (or Alt + Shift + S) and you’ll find a link to easily link to or embed your code in your website or blog. If you use wordpress, this plugin is designed to simplify embedding python code: https://wordpress.org/plugins/create-with-code/

Embed python code in an external website with create.withcode.uk

API

This service is currently provided for free for all for educational use.

If you use this service, the URL and IP address of the computer posting python code is logged to track usage.

Usage may have to be limited if this service is abused. Please get in touch if you have any questions.

Please note

All you need to do is post the python code to https://create.withcode.uk via HTTP with the following parameters:

Parameter: py_files:

The code you want to display or run

This can be the contents of one python code e.g.

for i in range(10,0,-1):
print(i)
print("Blast off")

or it can be a JSON collection of multiple files e.g.

{
"program.py":"with open('readme.txt') as f: \n\t print(f.read())",
"readme.txt":"You can read from and write to files with create.withcode.uk"
}

Parameter: mode:

The way you want the code to be displayed.

Values:

normal: (default) load the code in a normal window with full toolbar and ads

embed: load the code in an editor window ideal for embedding in another site (no ads, {+} button pops out into a new window)

run: displays the result of the code running rather than the code itself

Try it:

URL: https://create.withcode.uk

HTTP method: post

Result:

Continue ReadingUsing create.withcode.uk to embed python code in an external website