Language Selection

English French German Italian Portuguese Spanish

Python Leftovers

Filed under
  • Writing Makefiles for Python Projects | Bastian Venthur's Blog

    I'm a big fan of Makefiles. Almost all my side projects are using them, and I've been advocating their usage at work too.

    Makefiles give your contributors an entry point on how to do certain things like, building, testing, deploying. And if done correctly, they can massively simplify your CI/CD pipeline scripts as they can often just stupidly call the respective make targets. Most importantly, they are a very convenient shortcut for you as a developer as well.

  • Use this open source tool to monitor variables in Python

    When debugging code, you're often faced with figuring out when a variable changes. Without any advanced tools, you have the option of using print statements to announce the variables when you expect them to change. However, this is a very ineffective way because the variables could change in many places, and constantly printing them to a terminal is noisy, while printing them to a log file becomes unwieldy.

    This is a common issue, but now there is a simple but powerful tool to help you with monitoring variables: watchpoints.

    The watchpoint concept is common in C and C++ debuggers to monitor memories, but there's a lack of equivalent tools in Python. watchpoints fills in the gap.

  • How to use map, reduce and filter in Python

    In Python, functions are treated no different than regular objects like numbers and strings. You can assign a function to a variable and store it inside a data structure. You can pass a function to another function as one of its parameters. You can even define a function inside another function. Such functional programming approach in Python can be best illustrated by built-in functions called map(), filter(), and reduce().

    In this tutorial, we will see how to use map(), filter(), and reduce() in Python. While their functionalities can be equally achieved with list comprehension or explicit for-loops, these functions allow us to write short, simple, and concise code. For example, a problem that can be solved with 4-5 lines of code using an explicit for-loop can be done in 1-2 code lines using these functions. So, without further ado, let's get started and see each one of them with examples.

  • How to Handle CSV Files in Python – Linux Hint

    This article will cover a tutorial on handling “csv” files using Python. The term “csv” stands for “comma separated values” where each row or line contains text based values delimited by commas. In some cases, “semicolon” is also used instead of “comma” to separate values. However, this doesn’t make much difference to file format rules and the logic to handle both types of separators remains the same.

    CSV file format is most commonly used for maintaining databases and spreadsheets. The first line in a CSV file is most commonly used to define column fields while any other remaining lines are considered rows. This structure allows users to present tabular data using CSV files. CSV files can be edited in any text editor. However, applications like LibreOffice Calc provide advanced editing tools, sort, and filter functions.

  • How to Use Zip Function in Python – Linux Hint

    This article will cover a guide on “zip” function available in Python’s standard module library. This method allows you to combine and pair elements of multiple iterable objects. You can then run further logic on these pairs. In many cases, using a “zip” function is much more efficient and cleaner than using multiple, nested “for” loops.

  • Build a dice-rolling simulator in Python – Linux Hint

    The dice is a simple cube that generates any number from 1 to 6, and the dice simulator is a computer model that rolls the dice for the user. A dice rolling simulator can be implemented in different ways by Python. Six images will be required to create that will be used in the simulator. The Pillow module of Python is used to display any image in Python that is not installed by default. The dice rolling simulator can be implemented without GUI and GUI, as shown in this tutorial.

  • How to Use Python SimpleHTTPServer

    The main task of the webserver is to handle the HTTP requests from the client. It waits for the HTTP requests coming from the particular IP address and port number, handles the request, and sends the client’s response back. Python uses the SimpleHTTPServer module to create a web server instantly and easily serve the content of the file from the server. It can be used for file sharing also. For this, you have to enable this module with the location of the shareable files. This module comes with the Python interpreter. You don’t need to install it. Since this module is merged with the http.server module in python3, so you have to run http.server to run the webserver in python3. How web server can be used to handle HTTP request and share files, have been shown in this tutorial.

  • How to Convert Fahrenheit to Celsius using Python

    Both Fahrenheit and Celsius are used for temperature measurement. German physicist Daniel Gabriel Fahrenheit is the inventor of the Fahrenheit measurement scale, and the unit of this measurement is defined by the degree. The water freezes at 32 degrees Fahrenheit and water boils at 212 degrees Fahrenheit. Swedish astronomer Andres Celsius is the inventor of the Celsius measurement scale, and the unit of this measurement is also defined by the degree. The water freezes at 0 degrees Celsius, and water boils at 100 degrees Celsius. Different ways to convert the Fahrenheit scale to the Celsius scale using python script are shown in this tutorial.

  • How to Use pexpect in Python

    pexpect is a popular Python module for doing different types of automated tasks. Different types of interactive applications such as telnet, ssh, ftp, etc., can be automated using this module. It is a pure Python module, and it does not require a C compiler or TCL or Expect extensions like others expect modules. It can work easily by using a Python interpreter only. This module can be used in two ways. One way is to use the run() function, and another way is to use spawn class. The run() function is easy to use than the spawn class and performs the automated tasks quickly. The particular command or a program can be executed by the run() function that returns the output. This function can be used as the alternative to the os.system() function. The spawn class is more powerful than the run() function that can spawn a child program, interact with it by sending input, and waiting for the response. This module is installed in python3 by default. The two ways of using this module have shown in this tutorial.

More in Tux Machines

digiKam 7.7.0 is released

After three months of active maintenance and another bug triage, the digiKam team is proud to present version 7.7.0 of its open source digital photo manager. See below the list of most important features coming with this release. Read more

Dilution and Misuse of the "Linux" Brand

Samsung, Red Hat to Work on Linux Drivers for Future Tech

The metaverse is expected to uproot system design as we know it, and Samsung is one of many hardware vendors re-imagining data center infrastructure in preparation for a parallel 3D world. Samsung is working on new memory technologies that provide faster bandwidth inside hardware for data to travel between CPUs, storage and other computing resources. The company also announced it was partnering with Red Hat to ensure these technologies have Linux compatibility. Read more

today's howtos

  • How to install go1.19beta on Ubuntu 22.04 – NextGenTips

    In this tutorial, we are going to explore how to install go on Ubuntu 22.04 Golang is an open-source programming language that is easy to learn and use. It is built-in concurrency and has a robust standard library. It is reliable, builds fast, and efficient software that scales fast. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel-type systems enable flexible and modular program constructions. Go compiles quickly to machine code and has the convenience of garbage collection and the power of run-time reflection. In this guide, we are going to learn how to install golang 1.19beta on Ubuntu 22.04. Go 1.19beta1 is not yet released. There is so much work in progress with all the documentation.

  • molecule test: failed to connect to bus in systemd container - openQA bites

    Ansible Molecule is a project to help you test your ansible roles. I’m using molecule for automatically testing the ansible roles of geekoops.

  • How To Install MongoDB on AlmaLinux 9 - idroot

    In this tutorial, we will show you how to install MongoDB on AlmaLinux 9. For those of you who didn’t know, MongoDB is a high-performance, highly scalable document-oriented NoSQL database. Unlike in SQL databases where data is stored in rows and columns inside tables, in MongoDB, data is structured in JSON-like format inside records which are referred to as documents. The open-source attribute of MongoDB as a database software makes it an ideal candidate for almost any database-related project. This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MongoDB NoSQL database on AlmaLinux 9. You can follow the same instructions for CentOS and Rocky Linux.

  • An introduction (and how-to) to Plugin Loader for the Steam Deck. - Invidious
  • Self-host a Ghost Blog With Traefik

    Ghost is a very popular open-source content management system. Started as an alternative to WordPress and it went on to become an alternative to Substack by focusing on membership and newsletter. The creators of Ghost offer managed Pro hosting but it may not fit everyone's budget. Alternatively, you can self-host it on your own cloud servers. On Linux handbook, we already have a guide on deploying Ghost with Docker in a reverse proxy setup. Instead of Ngnix reverse proxy, you can also use another software called Traefik with Docker. It is a popular open-source cloud-native application proxy, API Gateway, Edge-router, and more. I use Traefik to secure my websites using an SSL certificate obtained from Let's Encrypt. Once deployed, Traefik can automatically manage your certificates and their renewals. In this tutorial, I'll share the necessary steps for deploying a Ghost blog with Docker and Traefik.