<?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 PäksTech</title><link>https://www.pakstech.com/categories/python/</link><description>Recent content in Python on PäksTech</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><copyright>2021 Janne Kemppainen All rights reserved</copyright><lastBuildDate>Mon, 03 Oct 2022 20:29:08 +0300</lastBuildDate><atom:link href="https://www.pakstech.com/categories/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Combine Multiple Filter Conditions in Python</title><link>https://www.pakstech.com/blog/python-multiple-filter/</link><pubDate>Mon, 03 Oct 2022 20:29:08 +0300</pubDate><guid>https://www.pakstech.com/blog/python-multiple-filter/</guid><description>&lt;p>This problem occurred when I was trying to think of an alternative way for returning the first item from a list that matches given constraints. Using if statements inside a for loop is the obvious way to comb through the items but the built-in &lt;code>filter()&lt;/code> function provides an interesting alternative.&lt;/p></description></item><item><title>Run Selected Python Unit Tests from the Command Line</title><link>https://www.pakstech.com/blog/python-select-unit-test/</link><pubDate>Sat, 07 Aug 2021 20:08:25 +0300</pubDate><guid>https://www.pakstech.com/blog/python-select-unit-test/</guid><description>&lt;p>It doesn&amp;rsquo;t always make sense to run the full suite of tests when you&amp;rsquo;re developing a part of a program. So how can you run only a portion of your Python unit tests on the command line?&lt;/p></description></item><item><title>Use StatsD to Measure Your Python App Metrics</title><link>https://www.pakstech.com/blog/python-statsd/</link><pubDate>Mon, 12 Jul 2021 10:40:29 +0300</pubDate><guid>https://www.pakstech.com/blog/python-statsd/</guid><description>&lt;p>If you&amp;rsquo;re a fan of DevOps, then you should also be enthusiastic about collecting telemetry from your production applications. &lt;a href="https://github.com/statsd/statsd">StatsD&lt;/a> is one solution that you could use to collect metrics in Python.&lt;/p></description></item><item><title>Python File Operations</title><link>https://www.pakstech.com/blog/python-file-operations/</link><pubDate>Fri, 21 May 2021 18:46:08 +0300</pubDate><guid>https://www.pakstech.com/blog/python-file-operations/</guid><description>&lt;p>Knowing how to handle files in your programming language of choice is an essential skill for any developer. After reading this post you should be comfortable doing file operations in Python.&lt;/p></description></item><item><title>Show a Progress Bar in Python</title><link>https://www.pakstech.com/blog/python-progress-bar/</link><pubDate>Sat, 13 Mar 2021 19:09:04 +0200</pubDate><guid>https://www.pakstech.com/blog/python-progress-bar/</guid><description>&lt;p>Python is a great language for writing command line scripts. When you need to run long running processes it is polite to indicate the overall progress to your user. You don&amp;rsquo;t want the user to think that your script has hanged and terminate the execution after a minute. Luckily, adding a progress indicator is really easy!&lt;/p></description></item><item><title>What is the Switch-Case Equivalent in Python?</title><link>https://www.pakstech.com/blog/python-switch-case/</link><pubDate>Sat, 06 Mar 2021 21:00:56 +0200</pubDate><guid>https://www.pakstech.com/blog/python-switch-case/</guid><description>&lt;p>Historically, the Python syntax hasn&amp;rsquo;t had a switch-case statement. In 2006 &lt;a href="https://twitter.com/gvanrossum?lang=en">Guido van Rossum&lt;/a>, the original author of Python, &lt;a href="https://www.python.org/dev/peps/pep-3103/">proposed different alternatives for the switch-case syntax in PEP 3103&lt;/a> but they all seemed to have some problems and the idea didn&amp;rsquo;t gain enough popular support. The proposal was therefore rejected. Python version 3.10 changes this.&lt;/p></description></item><item><title>Return Many Values as Attributes in Python</title><link>https://www.pakstech.com/blog/python-simplenamespace/</link><pubDate>Wed, 13 Jan 2021 19:43:01 +0200</pubDate><guid>https://www.pakstech.com/blog/python-simplenamespace/</guid><description>&lt;p>When you need to return complex data from a function you typically think of two options:&lt;/p>
&lt;ol>
&lt;li>put the values in a dictionary&lt;/li>
&lt;li>create a new object/class&lt;/li>
&lt;/ol>
&lt;p>The first option is simple to implement but you need to access the individual values by their keys. The second option allows you to access data via attributes and do custom calculations behind the scenes, but then you need to implement yet another class.&lt;/p>
&lt;p>&lt;strong>Is there something in Python that could give us easy attribute access without having to bother with custom classes?&lt;/strong>&lt;/p></description></item><item><title>Define a Python Script Inside a GH Actions Workflow File</title><link>https://www.pakstech.com/blog/gh-actions-python-script/</link><pubDate>Sat, 31 Oct 2020 16:38:14 +0200</pubDate><guid>https://www.pakstech.com/blog/gh-actions-python-script/</guid><description>&lt;p>GitHub Actions gives you lots of freedom to define custom workflows by combining different actions and running command line programs. Sometimes you might want to run small snippets of code, and that is already possible by running scripts from the command line with the &lt;code>run&lt;/code> keyword. What if you could write your Python script inside the workflow YAML file instead?&lt;/p></description></item><item><title>Dynamic Attributes in Python</title><link>https://www.pakstech.com/blog/python-dynamic-attributes/</link><pubDate>Tue, 20 Oct 2020 20:58:12 +0300</pubDate><guid>https://www.pakstech.com/blog/python-dynamic-attributes/</guid><description>&lt;p>When you define an object in Python you usually give it some attributes that hold the necessary pieces of information in a place that makes sense. However, Python does not limit the use of attributes to the set that were described at object creation time.&lt;/p></description></item><item><title>Chained Comparisons in Python</title><link>https://www.pakstech.com/blog/python-chained-comparisons/</link><pubDate>Wed, 07 Oct 2020 19:00:00 +0300</pubDate><guid>https://www.pakstech.com/blog/python-chained-comparisons/</guid><description>&lt;p>Can you chain comparison operations in Python? Yes you can, each comparison is evaluated pairwise so you can chain together as many of them you want.&lt;/p>
&lt;p>It can be easy to forget to use basic features like this if you come from a language that doesn&amp;rsquo;t support chained comparisons or if you&amp;rsquo;ve never seen them used in the wild. I&amp;rsquo;ve been using Python professionally for years but I have to admit that I still didn&amp;rsquo;t really know about this feature until recently.&lt;/p></description></item><item><title>Create Simple Python GUI Applications with Gooey</title><link>https://www.pakstech.com/blog/python-gooey/</link><pubDate>Thu, 21 May 2020 18:50:29 +0300</pubDate><guid>https://www.pakstech.com/blog/python-gooey/</guid><description>&lt;p>This time I&amp;rsquo;m going to show you how to create simple GUI applications in Python using a package called &lt;a href="https://github.com/chriskiehl/Gooey">Gooey&lt;/a>. It lets you turn (almost) any command line Python application into a GUI application with one line.&lt;/p></description></item><item><title>Create Your Own Python Packages</title><link>https://www.pakstech.com/blog/python-create-packages/</link><pubDate>Sat, 16 May 2020 16:32:25 +0300</pubDate><guid>https://www.pakstech.com/blog/python-create-packages/</guid><description>&lt;p>When programming in Python you&amp;rsquo;re used to installing packages from &lt;a href="https://pypi.org/">the Python Package Index (PyPI)&lt;/a>. But how do the packages end up there? How can I make my Python code installable? Let&amp;rsquo;s find out!&lt;/p></description></item><item><title>Backend With Python, How?</title><link>https://www.pakstech.com/blog/python-backend/</link><pubDate>Tue, 07 Apr 2020 20:39:58 +0300</pubDate><guid>https://www.pakstech.com/blog/python-backend/</guid><description>&lt;p>You want to be a Python backend developer but have no idea what you should learn? Choosing what to focus on can be difficult. In this blog post I hope to help you by discussing different types of backends and the technologies that you could use to build them.&lt;/p></description></item><item><title>Building URLs in Python</title><link>https://www.pakstech.com/blog/python-build-urls/</link><pubDate>Fri, 20 Mar 2020 13:19:59 +0200</pubDate><guid>https://www.pakstech.com/blog/python-build-urls/</guid><description>&lt;p>Building URLs is really common in applications and APIs because most of the applications tend to be pretty interconnected. But how should we do it in Python? Here&amp;rsquo;s my take on the subject.&lt;/p></description></item><item><title>Use Google Analytics to Show Popular Content on Your Static Blog</title><link>https://www.pakstech.com/blog/hugo-popular-content/</link><pubDate>Sat, 07 Mar 2020 13:08:13 +0200</pubDate><guid>https://www.pakstech.com/blog/hugo-popular-content/</guid><description>&lt;p>It is quite easy to recommend your most popular posts to your readers if you are running a WordPress site. What if you are using a static site generator such as Hugo instead? On this post you&amp;rsquo;ll learn how to add a popular posts section by using data from Google Analytics, and how to automate the whole process.&lt;/p></description></item><item><title>Dockerize Your Python Applications (Flask example)</title><link>https://www.pakstech.com/blog/dockerize-python/</link><pubDate>Wed, 12 Feb 2020 20:39:47 +0300</pubDate><guid>https://www.pakstech.com/blog/dockerize-python/</guid><description>&lt;p>Nowadays Docker containers seem to be all around us. With the rise of Kubernetes they are now even more relevant in businesses that choose to run their processes in public or private clouds.&lt;/p>
&lt;p>Another trending thing in the development world is Python which is especially huge in the machine learning field. In this post I&amp;rsquo;ll show you how to containerize your Python application in just a few minutes.&lt;/p></description></item><item><title>Environment Variables in Python</title><link>https://www.pakstech.com/blog/python-environment-variables/</link><pubDate>Wed, 22 Jan 2020 09:18:41 +0300</pubDate><guid>https://www.pakstech.com/blog/python-environment-variables/</guid><description>&lt;p>Environment variables are key-value pairs that are defined in your shell environment outside of the Python executable. You can access them in Python with the &lt;code>os.environ&lt;/code> mapping object.&lt;/p>
&lt;p>Environment variables are really useful for passing secret information or other configurations that you don&amp;rsquo;t want to pass as command line arguments. A good use case for example is a containerized application running in Docker or Kubernetes where you can configure the application using environment variables.&lt;/p></description></item><item><title>Three Dots in Python, What is the Ellipsis Object?</title><link>https://www.pakstech.com/blog/python-ellipsis/</link><pubDate>Sat, 04 Jan 2020 20:53:16 +0300</pubDate><guid>https://www.pakstech.com/blog/python-ellipsis/</guid><description>&lt;p>You might have stumbled on the Ellipsis object (&amp;hellip;) in Python and wondered what it is used for. It was originally introduced to be used in the &lt;a href="https://numpy.org/">Numeric Python&lt;/a> package for matrix slicing but nothing stops you from using it for other purposes too.&lt;/p></description></item><item><title>Use Make to Power Up Your Python Development</title><link>https://www.pakstech.com/blog/make-development/</link><pubDate>Thu, 12 Dec 2019 20:03:14 +0200</pubDate><guid>https://www.pakstech.com/blog/make-development/</guid><description>&lt;p>When you think of GNU Make what is the first thing that pops up to your mind? Perhaps you remember building C or C++ programs from source and automatically associate it with languages where you need to build the code before being able to run anything.&lt;/p>
&lt;p>However, Make can be a really powerful tool for your other projects too. In this article I&amp;rsquo;ll show you some examples on how to utilize Make for Python development. I&amp;rsquo;ll be using the &lt;a href="https://www.palletsprojects.com/p/flask/">Flask&lt;/a> web framework for demonstration purposes but these principles can be really adapted to any other project.&lt;/p></description></item><item><title>Install Python on Windows With Virtual Environments</title><link>https://www.pakstech.com/blog/python-windows/</link><pubDate>Fri, 01 Nov 2019 20:39:26 +0200</pubDate><guid>https://www.pakstech.com/blog/python-windows/</guid><description>&lt;p>Today I wanted to install Python natively on my Windows machine. Nowadays it is super easy as python can be installed straight from the Microsoft Store. So if you need to have Python on Windows I really recommend that you go to the Microsoft Store from the Start menu, search for Python and install it from there.&lt;/p></description></item><item><title>Stop Worrying About Python Code Formatting</title><link>https://www.pakstech.com/blog/python-black/</link><pubDate>Fri, 10 May 2019 16:15:20 +0300</pubDate><guid>https://www.pakstech.com/blog/python-black/</guid><description>&lt;p>Wouldn&amp;rsquo;t it be nice if you didn&amp;rsquo;t have to worry about code formatting to make the linter happy? What if you didn&amp;rsquo;t need to complain about minor formatting issues every time you are reviewing code? Can&amp;rsquo;t agree on a common code style with your team so your codebase doesn&amp;rsquo;t have a consistent look and feel? You are just starting a new Python project? It might be the right time to try Black.&lt;/p>
&lt;p>&lt;a href="https://github.com/python/black">&lt;img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black" loading="lazy" />
&lt;/a>&lt;/p></description></item><item><title>Show Twitter Follower Count with Google Spreadsheets as a Backend</title><link>https://www.pakstech.com/blog/twitter-followers-google-spreadsheet/</link><pubDate>Mon, 15 Apr 2019 21:00:26 +0300</pubDate><guid>https://www.pakstech.com/blog/twitter-followers-google-spreadsheet/</guid><description>&lt;p>I was quite surprised to get my first Twitter followers after linking my earlier blog post about &lt;a href="https://www.pakstech.com/blog/develop-with-subsystem-for-linux/">developing with Windows Subsystem for Linux&lt;/a> to Twitter as I&amp;rsquo;ve never really had a social media presence outside of my own circles. This gave me the idea to track how my Twitter following develops over time when I start from zero.&lt;/p>
&lt;p>Given that I&amp;rsquo;m using a static blogging environment there is no server that could actively serve this data and routing users to my home server is definitely not an option. This is where Google Spreadsheets comes in handy as it turns out that you can fetch data in CSV format without having to use strong authentication! Read more to find out how I built the follower chart below.&lt;/p></description></item></channel></rss>