f-Strings

One of the delights of coming back to Python in an intensive way after many years is some of the new ways to do the usual things that I hadn’t learned before.

In this case, I am finding the use of “f-strings” (introduced in Python 3.6, described in PEP 498) to be quite delightful.

print(f"Warning: {sys.argv[2]} exists!")

The previous syntax for format strings always slipped away from my memory, but these seem a lot stickier, and they give me a lot of freedom to just keep writing.

Python is not the greatest language in the universe, but it can allow a lot of fluency that I never experienced in other languages.

Keeping Secrets in Code

The problem of keeping secrets – usernames, passwords, API keys, etc, in code that you write is a pretty old problem. I haven’t had a solution that I liked – especially when I am putting code up on github, for a long time.

Until now. I am putting things like that in a “secrets” file, or in environment variables, which are easy to access from your code, but don’t show up in your code repository. Here’s an example in Python of keeping a “secrets” file that the script can access, and then yoinking its contents into a dictionary for easy reference:

def getSecrets():

def getSecrets():
  SECRETFILE = os.environ["SECRETFILE"]
  with open(SECRETFILE , "r") as scrts:
    return dict(line.strip().split("=====") for line in scrts)

secrets = getSecrets()

api_url = secrets["Test API URL"]
api_key = secrets["Test API Key"]

""" The file itself would look like this:

API Key=====zEV}pF_vn4g35Ye:
API URL=====https://example.com
..."""

Flights of fancy – part 5

In previous posts I has imagined the possibilities of high-strength carbon-based nanomaterials on various industries, and a variety of currently impossible applications.  In this post I imagine some (to me anyway) interesting applications of these tools in times of crisis.

I will start with a small-scale crisis dismayingly common in the Canadian north, but it is the sort of thing that happens anywhere that is hard to get to via regular transit channels; an unexpected medication shortage.

Imagine a small community in the Northwest Territories beset with the unfortunately common problem of diabetes and hypertension.  Both diseases can be mitigated by medication, but that medication is needed regularly or the health consequences are disasterous.  A fire in winter in the clinic could easily destroy a six-month supply of life-sustaining medication in minutes, and while the medications are not hugely expensive, getting them to the people that need them is.  However, imagine the difference if a hospital pharmacist in Edmonton gets a call from a satellite phone while the clinic is still burning from the local band leader – they could outline their urgent medication needs to the hospital, and the pharmacist could make up a one-month supply of vital medications, and pack them in an insulated box and take them up to the roof, where a dozen medi-drones are housed, charging their batteries for just this moment.  The medication box gets locked with a code and clipped to a small, wing-shaped dririgible of perhaps four by two metres, which immediately lifts off and heads north.  During the day the solar cells on the top of the drone charge the batteries, and it travels day and night at a modest top speed of 180 kms per hour, fast enough to make headway against even strong winds, and reaching the remote community in 10-20 hours.  It drops to the local basketball court/landing pad after receiving the coded signal from the local nurse’s phone, unclips the medication box which they have received a code for unlocking, and then the drone heads back to Edmonton.

It sounds like science fiction, but the technology exists today to do this.

Also imagine a popular hiking trail in a remote area like the Grand Canyon.  At any given time there are a few dozen people exploring an amazing landscape with significant challenges.  However, instead of each person or group carrying everything they might need, each group has a small, solar-powered blimp following them as they explore the trails.  Capable of carrying 100 kgs of gear the hikers can travel more lightly, with more gear, than ever before.  Buy floating 20-1000 metres above the hikers, their personal blimp can provide hyper-local terrain information and access cellular data networks not reachable from the canyon floor for weather prediction and network access.  If someone falls or is bitten by a snake, instead of having to split a party up or hike out in extreme discomfort or die, their blimp can rise to the level where it can contact the blimps of other hikers or park rangers in the area and summon help to the exact spot needed.

On a larger scale, imagine a massive, aircraft-carrier-sized dirigible, housing a 1000 aid workers, doctors and nurses, engineers and rescue workers, hundreds of tons of emergency food, shelter and medical supplies.  These disaster response teams already exist and are deployed by goverments, but if they had the ability to deploy anywhere, and were mobile enough to get people and equipment exactly where they are needed in the event of an earthquake, flood or other disaster the reduction in suffering could be huge.  Any dirigible large enough to provide the personel, equipment and supplies needed for major disaster relief would also be large enough to generate and store significant power to help light, heat and shelter people in the affected area.

The research and development of the central technologies is already well underway  – we just need to flex our imaginations to what is possible tomorrow, rather that what is immediately profitable today.