Python Leftovers

-
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.
-

- Login or register to post comments
Printer-friendly version- 2333 reads
PDF version
More in Tux Machines
- Highlights
- Front Page
- Latest Headlines
- Archive
- Recent comments
- All-Time Popular Stories
- Hot Topics
- New Members
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.
|
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.
|
today's howtos
|








.svg_.png)
Content (where original) is available under CC-BY-SA, copyrighted by original author/s.

Recent comments
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago