Getting started is really easy:
- Import the
- Add an
onloadhandler to your <body> tag to boot Brython
- 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.
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", "user2@address2"] hashed_emails = [hashlib.sha256(bytes(mail.lower(), "ascii")).hexdigest() for mail in plain_emails]