Blog

All the articles, tutorials, and discussions written at Python for the Lab. Learn from real-world use cases, and join the discussion to deepen your knowledge and understanding. We focus on patterns and topics that are useful for researchers working in a lab. From automation to data storage. If you don't find what you are looking for, drop us a line!.

Get all the information directly to your inbox

Get relevant information, unsubscribe at any time.
How to control an Arduino from the computer using Python March 27, 2021 Instructions to build the Python for the Lab DAQ The PFTL DAQ is the ideal companion to follow the book Python for the Lab Building the device itself is not part of the book because it focuses on Python best practices and not on lower-level electronics. In this article, we will quickly see how to build the device to follow the book to its fullest. Read Article
Slots in Python March 21, 2021 Using slots in Python: limit dynamic attribute creation and improve speed When we create classes, one of the biggest challenges is understanding how to handle dynamic attribute creation. Slots have the benefit of limiting attribute creation at runtime. In this article, we will explore how slots work, including a quick overview of how classes store attributes internally. Read Article
Controlling basler cameras with python Feb. 27, 2021 Getting started with Basler cameras Basler puts continuous effort into maintaining PyPylon, the Python bindings for their drivers. This tutorial will focus on learning how to get started with the cameras and how to leverage the existing Pylon Viewer to speed up our development. Read Article
Illustration of the idea of singletons in Python Jan. 16, 2021 Singletons: Instantiate objects only once Singletons are a programming pattern that is often overlooked. However, in Python we use it all the time. In this article we explore what singletons are, and how we can define our own. Read Article
twingo.gif Sept. 19, 2020 How Python for the Lab helped the developer of Twingo Twingo allows you to acquire and generate analog signals with ease. Learn how Michal leveraged Python for the Lab to achieve it. Read Article
Multiprocessing on Windows and Linux June 13, 2020 Differences between multiprocessing on Windows and Linux Multiprocessing does not work in the same way for Windows and Linux systems. We explore the differences between the operating systems and what we can do to mitigate the problems that arise. Read Article
Using else with loops May 25, 2020 Python Tip: Using Else with Loops Most likely, you are aware of how to use the else statement with an if clause. However, Python also allows us to use them with loops. They are straightforward to understand and open some exciting possibilities. Before continuing, remember that else in this context should be called no-break. Read Article
Python Tips Matplotlib Saving May 18, 2020 Python Tip: Ready to Publish Matplotlib Figures Saving figures for publications, presentations, books, or websites can be a cumbersome task but doesn't need to be. In this Python Tip, we will see how to create images using Matplotlib that are ready to be embedded. We will take care of the most important aspects: shape, font sizes, and resolution. You won't have to tinker ever again with random parameters until the result is right. Read Article
Descritpors in Python May 16, 2020 Data Descriptors: Bringing Attributes to the Next Level Descriptors in Python allow us to control how attributes of classes are accessed or modified. A pattern often encountered is defining properties to use setter and getter methods encapsulated as if they were a single attribute. In this article, we will dig into how the property decorator works, to understand how to implement our solutions. Read Article
Python tips sets May 11, 2020 Python Tips: Using Sets Sets are a great tool to complement lists and tuples. Learn how to perform basic operations such as intersections and unions. Read Article
Generators Iterables Iterators April 10, 2020 Generators, Iterables, Iterators in Python: When and Where Generators, Iterables, and Iterators are some of the most used tools in Python. However, we don't often stop to think about how they work, how we can develop our generators and iterables. Once you learn what you can do with them, it is possible to expand your toolbox and make your code much more efficient and pythonic. Read Article
How to control an Arduino from the computer using Python Feb. 4, 2020 How to control an Arduino from the computer using Python Arduinos may be one of the most disruptive electronic developments of the past decade. They opened a world of possibilities to quickly prototype solutions in professional settings but also opened the door for enthusiasts to learn about electronics and microcontrollers. In this article, we are going to see how to get started with an Arduino board and how to control it from a computer using Python. Read Article
How to create a setup file for your project Jan. 20, 2020 How to create a setup file for your project When you develop software, at some point you will want other people to be able to use what you have built. Sometimes it is handy if you can quickly use the code you developed yourself in the past on a new machine or a different virtual environment. We have already seen that for importing to work properly, it is very important to have well-defined packages, and that Python knows where to find them. Read Article
Screenshot PFTL Jan. 2, 2020 Website Redesigned and Improved To start a new year, we have decided to give Python for the Lab a complete new look. We hired a very talented designer to work on improving the look and feel of the website. It is incredible how many different details must be taken into account when deciding how a website should look. From color palette, and icons, to typography. We really hope you enjoy the new version of the website. We know we do love how it looks now! Read Article
Complete guide to imports Oct. 4, 2019 Complete Guide to Imports in Python: Absolute, Relative, and More Importing packages and modules can be daunting at first. This is a deep dive into how the mechanism works and how can be used in different contexts. Read Article
Handling and sharing data between threads Aug. 6, 2019 Handling and Sharing Data Between Threads When working with threads in Python, you will find very useful to be able to share data between different tasks. One of the advantages of threads in Python is that they share the same memory space, and thus exchanging information is relatively easy. However, some structures can help you achieve more specific goals. Read Article
Starting and Synchronizing Threads Aug. 6, 2019 Starting and Synchronizing Threads If you have developed code for long enough, probably you have faced the situation in which a task takes longer to complete and in the meantime, your program can't perform any other task. Most likely you can't even politely cancel what the program is doing, you will have to resort to the Ctrl+C strategy. Fortunately, Python has different approaches to overcome these issues. Read Article
Monkey patching and its consequences June 18, 2019 Monkey Patching and its consequences Replacing methods at runtime can give you plenty of choices when using external libraries. However, it also comes with some risks. In this article we discuss different approaches and their caveats when monkey patching methods in Python. Read Article
Duck typing, or how to check variable types June 11, 2019 Duck Typing, or how to check variable types The name duck typing has its root in the expression If it walks like a duck and it quacks like a duck, then it must be a duck. Which means that if you want to know whether you are dealing with a duck or not, you only care about how it looks like and how it behaves rather than actually checking to what species the animal belongs. Read Article
Intro to python lambda functions March 17, 2019 Intro to Python Lambda Functions Some time ago, Python introduced in its syntax the possibility to define functions using lambda instead of def. These functions are called anonymous and are very common in other languages such as Javascript. However, in Python, they seem a bit obscure and are often either overlooked or misused. In this article, we are going to introduce the lambda functions and discuss where and how to use it. Read Article

Get all the information directly to your inbox

Get relevant information, unsubscribe at any time.