And how to get example code

I mostly write about programming in Python (and sometimes, Julia) for Data Visualization and Data Science but occasionally I stray into other areas of science and technology.

If you’d like to know when I publish new articles, please consider subscribing to my free, occasional, newsletter here.

You can download the code for several articles from my Github page.

It’s much more powerful than 'switch’. I explain with help from Harry Potter and a dead parrot

Photo by Ashkan Forouzani on Unsplash

Python has, at long last, got itself a switch statement. Hooray!

But it’s not your common or garden switch statement as you would find in C or Java — of course not, this is Python. Python 3.10 implements Structural Pattern Matching which can be as simple as a switch statement but can also be rather more.

I covered the basics of Structural Pattern Matching here — this article goes into the topic a bit further, looking at capturing matched patterns (getting the value of a match that could be more than one value) and adding conditions to patterns.

But, first…

The Switch statement on steroids

Photo by Teo Duldulao on Unsplash

Python 3.10 has implemented the switch statement — sort of. The switch statement in other languages such as C or Java does a simple value match on a variable and executes code depending on that value.

It can be used as a simple switch statement but is capable of much more.

That might be good enough for C but this is Python, and Python 3.10 implements a much more powerful and flexible construct called Structural Pattern Matching. It can be used as a simple switch statement but is capable of much more.

Let’s take the simple switch case. Below is…

Python $59k, JavaScript $56k*. Which programming language should you learn if you want to start a career in software development

Photo by Michael Dziedzic on Unsplash

You could choose a language by going to the Stackoverflow survey website, find the highest paid language and learn that.

It’s a strategy. But not necessarily a good one.

For interest, here are the salaries reported by the Stackoverflow Developer’s Survey, 2020.

Using the TextBlob and VADER libraries for Sentiment Analysis is easy but how accurate are they

Photo by Tengyart on Unsplash

Sentiment Analysis is not an exact science. Natuaral language is full of strange expressions, words that mean more than one thing, idioms, sarcasm and any number of things that make the extraction of meaning difficult. Look at the these two sentences.

“I know why I keep making the same mistakes — I don’t think!”

“Sentiment Analysis is accurate in all circumstances — I don’t think!”

In the first sentence the phrase “I don’t think” explains the first part of the sentence but in the second it is sarcastic and negates the meaning of the preceding part of the sentence. …

Would you like to distribute or sell your articles and documents electronically? Engage your fans and readers by giving them access to downloads that they can enjoy reading on their own devices?

Photo by Maarten van den Heuvel on Unsplash

If you want to publish a novel or a textbook, you can do this through commercial outlets like Amazon’s KDP, Barnes and Noble Press or Rakuten Kobo. But this is not really an appropriate route for smaller documents or articles.

So, what if you want to reward your patrons with extra downloadable content, or make a short compilation of previous work for your faithful followers, or even sell short-form content from your website or online store? …

Data visualization

To create a truly interactive app with Dash you need to use callbacks. You can achieve the same thing with Plotly and Flask.

The app and code — image by autho

It may seem as if I have something against Dash. Honestly, I haven’t; it’s a fine product, comes with a lot of support from Plotly and does what it is intended to do, well.

But, as I attempted to demonstrate in a previous article, there is no need to write HTML in Python (as Dash requires you to do) when you can write it in HTML! …

Data Visualization

Why use Dash when Plotly plus Flask is easy and more flexible

A multi-page web app using Plotly and Flask — image by author

Why would you want to write HTML in Python? It baffles me. But that is what you need to do if you want to write a Dash app.

While I understand that there is a certain amount of satisfaction in having all your code in a single file, it seems to me that if you know enough about HTML to code it in a different language then you certainly know enough to write it in HTML!

I’d love for Dash to be the solution to writing web visualization apps but I’m not convinced.

Consider the following:

  1. A Dash app is…

This is a brief introduction to creating and running a Flask app, the use of HTML templates and how to create multi-page web apps using Flask routes.

The Flask logo — Copyright 2010 Pallets, used with permission

Flask is a web application micro-framework which means it is a very lightweight library for developing web apps. Creating your first Flask app is easy but first you will need to install it with pip or conda, for example:

pip3 install flask

Next, open a new directory and create a file with the following code:

from flask import Flaskapp = Flask(__name__)@app.route(‘/’)
def root():
return “Hello”

The code is pretty straightforward. The first line imports the Flask library; the second creates a Flask object (that will be run); and the rest of it defines a route. A route…

Citizen Science

There may be an asteroid heading our way — you could help find it. There may be potential treatments for Aids, Covid-19 or cancer — you could help identify them.

NASA’s OSIRIS-REx spacecraft studies asteroids — image courtesy of NASA

When Buzz Aldrin guided himself, and Neil Armstrong, to the surface of the moon on July, 20th, 1969, he was aided by a computer that was the first such device built with integrated circuits and, unsurprisingly, was the state of the art at the time.

That was over 50 years ago, so of course, you would expect computers to have got better. But how much? Ten times more powerful, 100 times, a 1000 times, perhaps. Maybe you’d be surprised to know that the smartphone in your pocket is 100,000 times more powerful than Aldrin’s computer.

Having a phone that is…

Alan Jones

Technology, science and programming. Subscribe to my newsletter here: . Web page:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store