Won’t Allow Python Files – Use

I’ve started experimenting with Brython, the project that allows you to use Python code in your browser. The first problem I’ve hit is that doesn’t let you edit Python files in projects.

We need an online coding environment for the Manchester CoderDojo so I’ve switched to Glitch. That works just fine. See:!/mcr-coderdojo-jul2018

Brython: Python for Scripting Webpages

I’ve just discovered Brython a project that let me script webpages using Python instead of JavaScript.

Getting started is really easy:

  1. Import the brython.js library
  2. Add an onload handler to your <body> tag to boot Brython
  3. Write your code inside <script type=”text\python”> tags

Here’s how to use the translate function code from my previous post.

Note that the translation won’t work unless you set up your own account key on the Google Translate API. Drop me a line if you’d like an IP white-listed.

I’m sure there will be gotchas using Brython. I will spend some time investigating further.

Python Snippet to Hash Email Addresses

I wanted to process some email address data today but hide the real email addresses. To do that I chose to run the SHA-256 hash over the email address data. Here’s the python snippet I used to convert the plain emails to the hashed versions (ignoring any emails with anything other than ASCII characters for simplicity):

import hashlib

plain_emails = ["user1@address1",

hashed_emails = [hashlib.sha256(bytes(mail.lower(), "ascii")).hexdigest()
                 for mail
                 in plain_emails]