<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Michael’s Domain</title><link>https://jeltsch.org/en/tags/python/</link><description>Recent content in Python on Michael’s Domain</description><generator>Hugo</generator><language>en-us</language><copyright>Copyright © 2002 - 2026 Michael Jeltsch.</copyright><lastBuildDate>Fri, 24 Jul 2026 00:18:18 +0300</lastBuildDate><atom:link href="https://jeltsch.org/en/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Python rules our plants</title><link>https://jeltsch.org/en/flint2/</link><pubDate>Wed, 24 Dec 2025 00:00:00 +0000</pubDate><guid>https://jeltsch.org/en/flint2/</guid><description>&lt;p&gt;In 2025, we updated our 12-year-old router (the Asus RT-AC66U, WiFi 5/IEEE 802.11ac) and replaced it with a WiFI 6 
 &lt;a href="https://www.gl-inet.com/products/gl-mt6000/" target="_blank" rel="noopener noreferrer nofollow"&gt;Flint 2 (GL-MT6000)&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
. While the default user interface of the Flint 2 is pretty basic, its advanced setup is a powerhouse. When you click &amp;ldquo;Advanced Setup&amp;rdquo;, you can access the underlying 
 &lt;a href="https://openwrt.org/" target="_blank" rel="noopener noreferrer nofollow"&gt;OpenWRT&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 user interface. OpenWRT is a Linux distribution for routers. And unsurprisingly, it is very powerful. A year ago, we started to use a 
 &lt;a href="https://phlizon.eu/products/phlizon-pl1000-qb-full-spectrum-led-grow-light" target="_blank" rel="noopener noreferrer nofollow"&gt;LED array&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 to help our plants survive the winter. To automatically operate the lights, we use a 
 &lt;a href="https://kb.shelly.cloud/knowledge-base/shelly-plus-plug-s-v2" target="_blank" rel="noopener noreferrer nofollow"&gt;Shelly smart plug&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 via a Python script that calculates the light levels and electricity prices (using 
 &lt;a href="https://www.sahkonhintatanaan.fi/sahkon-hinta-api" target="_blank" rel="noopener noreferrer nofollow"&gt;the sähkönhintatänään API&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 to get the price data) and switches the plant lights only on when both light levels and electricity prices are low. Today, we moved this Python script from my desktop computer to the Flint 2 router. There are thousands of installable packages available for OpenWRT (directly from the router UI: Applications &amp;gt; Plug-ins). To make my Python script work on the router, we first needed to install the openssh-server to get shell access (btw. the p/l combo is root/&amp;ldquo;same password as for the web UI&amp;rdquo;, the router correctly opens the access only to the local network). We also installed python3 and python3-pip and then pip-installed the two non-standard packages 
 &lt;a href="https://pypi.org/project/ShellyPy/" target="_blank" rel="noopener noreferrer nofollow"&gt;ShellyPy&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 (to address the smart plugs) and 
 &lt;a href="https://pypi.org/project/astral/" target="_blank" rel="noopener noreferrer nofollow"&gt;astral&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 (to calculate the dark/bright periods for any given day at Helsinki latitude, which is around 60°North). We just needed to add an entry to the crontab to run the script once every hour. Since you are logged in as root, you just need to execute crontab -e and add this line to the crontab &lt;code&gt;0 * * * * python3 /root/plantlight.py&lt;/code&gt; and restart the cron daemon (which you can do via the OpenWRT UI under &amp;ldquo;System &amp;gt; Startup&amp;rdquo;).&lt;/p&gt;</description></item><item><title>Python Virtual Environments</title><link>https://jeltsch.org/en/virtual_environment_for_python/</link><pubDate>Mon, 16 Jun 2025 00:00:00 +0000</pubDate><guid>https://jeltsch.org/en/virtual_environment_for_python/</guid><description>&lt;p&gt;There are many different ways to run Python in a virtual environment. I have used mostly conda (together with anaconda), but I frequently end up doing work on machines that do not have it installed. Hence, I have been recently starting to use the &amp;ldquo;inbuilt&amp;rdquo; virtual environment. If you are working on a Python project in a directory, these are the steps to start using it:&lt;/p&gt;</description></item><item><title>Multiple Python versions on Ubuntu 20.04</title><link>https://jeltsch.org/en/multiple_python_versions_on_ubuntu_20_04/</link><pubDate>Fri, 30 Apr 2021 00:00:00 +0000</pubDate><guid>https://jeltsch.org/en/multiple_python_versions_on_ubuntu_20_04/</guid><description>&lt;p&gt;Adding a new python version to Ubuntu 20.04 (for my system it is the 3rd version after 2.7 and 3.8):
&lt;code&gt;sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 3&lt;/code&gt;&lt;/p&gt;</description></item><item><title>Python für Kinder</title><link>https://jeltsch.org/en/python_f_r_kinder/</link><pubDate>Thu, 05 May 2016 00:00:00 +0000</pubDate><guid>https://jeltsch.org/en/python_f_r_kinder/</guid><description>&lt;p&gt;Mein Sohn lernt gerade Programmieren. Und es macht Spass. Zuerst haben wir zusammen ein bischen in html und php programmeirt, da er ein Online-Quiz auf seiner Website machen wollte. Danach haben wir angefangen, das (deutsche) Buch &amp;ldquo;Python für Kids&amp;rdquo; (
 &lt;a href="http://python4kids.net" target="_blank" rel="noopener noreferrer nofollow"&gt;http://python4kids.net&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
) durchzuarbeiten. Ich habe Python gewählt, weil es eine moderne, leicht zu lesende Sprache ist. Sie ist heute wahrscheinlich die erste Wahl für angehende Programmierer. Python ist Open Source, einfach auf allen Betriebssystemen zu installieren und leistungsfähige Programme können schon nach einer kurzen Lernphase geschrieben werden. &amp;ldquo;Python für Kinds&amp;rdquo; verwendet das 
 &lt;a href="http://pythonturtle.org/" target="_blank" rel="noopener noreferrer nofollow"&gt;Turtle-Modul&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
, das eine grafikorientierte Einführung ins Programmieren ermöglicht. Die Grafik oben ist z.B. eines der Ergebnisse.Python ist auch eine sehr gute Wahl für Biologen und Bioinformatiker. Da Python eine Mehrzweck-Sprache ist, ist man nicht auf bestimmte Aufgaben beschränkt (wie z.B mit R). Es gibt mit 
 &lt;a href="http://biopython.org/wiki/Main_Page" target="_blank" rel="noopener noreferrer nofollow"&gt;Biopython&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 ein sehr gutes Modul für den Umgang mit DNA und Proteinsequenzen (und sogar 3D-Strukturen).&lt;/p&gt;</description></item><item><title>Python for Kids (and bioinformaticians)</title><link>https://jeltsch.org/en/python_for_kids_and_bioinformaticians/</link><pubDate>Sat, 12 Mar 2016 00:00:00 +0000</pubDate><guid>https://jeltsch.org/en/python_for_kids_and_bioinformaticians/</guid><description>&lt;p&gt;I started to teach my son programming and we both are enjoying it. First we did a bit of html/php since he wanted to make an online quiz on his website, but now we started to work through the (German) book &amp;ldquo;Python für Kids&amp;rdquo; (
 &lt;a href="http://python4kids.net" target="_blank" rel="noopener noreferrer nofollow"&gt;http://python4kids.net&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
). I chosen Python because it&amp;rsquo;s a modern, easy-to-read language, and nowadays probably the most popular first choice for starting programmers. It&amp;rsquo;s open source, easy to install on any system and you can get write powerful programs after a short learning period. Python for Kids uses the 
 &lt;a href="http://pythonturtle.org/" target="_blank" rel="noopener noreferrer nofollow"&gt;Turtle&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
 module, which enables a graphics-oriented introduction into programming. The graphics on the left is one of the results. Another very useful Python teaching resource for kids is 
 &lt;a href="https://www.codeclubworld.org/" target="_blank" rel="noopener noreferrer nofollow"&gt;Code Club&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
.Python is also a very good choice for biologists and bioinformaticians, but since it is a multi-purpose language, you don&amp;rsquo;t limit yourself to certain tasks. There is 
 &lt;a href="http://biopython.org/wiki/Main_Page" target="_blank" rel="noopener noreferrer nofollow"&gt;Biopython&amp;nbsp;






 
 
 
 &lt;svg class="svg-inline--fa fas fa-up-right-from-square fa-2xs" fill="currentColor" aria-hidden="true" role="img" viewBox="0 0 512 512" overflow="visible"&gt;&lt;use href="#fas-up-right-from-square"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;
, which is a very good toolset for the handling of DNA and protein sequences and even 3D structures.&lt;/p&gt;</description></item></channel></rss>