Feeds

Design System December Updates

Planet KDE - Sun, 2024-12-08 12:58

Hey team!

Back with a series of updates on the Plasma Design System work that we are doing. All videos contain English captions.

Leave your feedback or let us know if you have any questions.

Categories: FLOSS Project Planets

Dries Buytaert: Drupal CMS: the official name for Drupal Starshot

Planet Drupal - Sun, 2024-12-08 11:34

We're excited to announce that "Drupal CMS" will be the official name for the product developed by the Drupal Starshot Initiative.

The name "Drupal CMS" was chosen after user testing with both newcomers and experienced users. This name consistently scored highest across all tested groups, including marketers unfamiliar with Drupal.

Participants appreciated the clarity it brings:

Having the words CMS in the name will make it clear what the product is. People would know that Drupal was a content management system by the nature of its name, rather than having to ask what Drupal is. I'm a designer familiar with the industry, so the term CMS or content management system is the term or phrase that describes this product most accurately in my opinion. I think it is important to have CMS in the title.

The name "Drupal Starshot" will remain an internal code name until the first release of Drupal CMS, after which it will most likely be retired.

Categories: FLOSS Project Planets

Freelock Blog: Show a mix of future and past events

Planet Drupal - Sun, 2024-12-08 10:00
Show a mix of future and past events Anonymous (not verified) Sun, 12/08/2024 - 07:00 Tags Advocacy Site Blog ECA Automation Drupal Planet Drupal

Another automation we did for Programming Librarian, a site for librarians to plan educational programs, involved events. They wanted to always feature 3 events on the home page, and the most important events were in the future.

Categories: FLOSS Project Planets

Real Python: How to Run Your Python Scripts and Code

Planet Python - Sun, 2024-12-08 09:00

Running a Python script is a fundamental task for any Python developer. You can execute a Python .py file through various methods depending on your environment and platform. On Windows, Linux, and macOS, use the command line by typing python script_name.py to run your script. You can also use the python command with the -m option to execute modules. This tutorial covers these methods and more, ensuring you can run Python scripts efficiently.

By the end of this tutorial, you’ll understand that:

  • Running a Python .py script involves using the python command followed by the script’s filename in the terminal or command prompt.
  • Running Python from the command prompt requires you to open the command prompt, navigate to the script’s directory, and execute it using python script_name.py.
  • Running a .py file in Windows can be done directly from the command prompt or by double-clicking the file if Python is associated with .py files.
  • Running a Python script without Python installed is possible by using online interpreters or converting scripts to executables, but it’s more flexible to install Python and run scripts natively.

To get the most out of this tutorial, you should know the basics of working with your operating system’s terminal and file manager. It’d also be beneficial for you to be familiar with a Python-friendly IDE or code editor and with the standard Python REPL (Read-Eval-Print Loop).

Free Download: Get a sample chapter from Python Tricks: The Book that shows you Python’s best practices with simple examples you can apply instantly to write more beautiful + Pythonic code.

Take the Quiz: Test your knowledge with our interactive “How to Run Your Python Scripts” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

How to Run Your Python Scripts

One of the most important skills you need to build as a Python developer is to be able to run Python scripts and code. Test your understanding on how good you are with running your code.

What Scripts and Modules Are

In computing, the term script refers to a text file containing a logical sequence of orders that you can run to accomplish a specific task. These orders are typically expressed in a scripting language, which is a programming language that allows you to manipulate, customize, and automate tasks.

Scripting languages are usually interpreted at runtime rather than compiled. So, scripts are typically run by some kind of interpreter, which is responsible for executing each order in a sequence.

Python is an interpreted language. Because of that, Python programs are commonly called scripts. However, this terminology isn’t completely accurate because Python programs can be way more complex than a simple, sequential script.

In general, a file containing executable Python code is called a script—or an entry-point script in more complex applications—which is a common term for a top-level program. On the other hand, a file containing Python code that’s designed to be imported and used from another Python file is called a module.

So, the main difference between a module and a script is that modules store importable code while scripts hold executable code.

Note: Importable code is code that defines something but doesn’t perform a specific action. Some examples include function and class definitions. In contrast, executable code is code that performs specific actions. Some examples include function calls, loops, and conditionals.

In the following sections, you’ll learn how to run Python scripts, programs, and code in general. To kick things off, you’ll start by learning how to run them from your operating system’s command line or terminal.

How to Run Python Scripts From the Command Line

In Python programming, you’ll write programs in plain text files. By convention, files containing Python code use the .py extension, and there’s no distinction between scripts or executable programs and modules. All of them will use the same extension.

Note: On Windows systems, the extension can also be .pyw for those applications that should use the pythonw.exe launcher.

To create a Python script, you can use any Python-friendly code editor or IDE (integrated development environment). To keep moving forward in this tutorial, you’ll need to create a basic script, so fire up your favorite text editor and create a new hello.py file containing the following code:

Python hello.py print("Hello, World!") Copied!

This is the classic "Hello, World!" program in Python. The executable code consists of a call to the built-in print() function that displays the "Hello, World!" message on your screen.

With this small program ready, you’re ready to learn different ways to run it. You’ll start by running the program from your command line, which is arguably the most commonly used approach to running scripts.

Using the python Command

To run Python scripts with the python command, you need to open a command-line window and type in the word python followed by the path to your target script:

Windows PowerShell PS> python .\hello.py Hello, World! PS> py .\hello.py Hello, World! Copied! Shell $ python ./hello.py Hello, World! Copied! Read the full article at https://realpython.com/run-python-scripts/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: Using and Creating Global Variables in Your Python Functions

Planet Python - Sun, 2024-12-08 09:00

In Python, global variables are accessible across your entire program, including within functions. Understanding how Python handles global variables is key to writing efficient code. This tutorial will guide you through accessing and modifying global variables in Python functions using the global keyword and the globals() function. You’ll also learn to manage scope and avoid potential conflicts between local and global variables.

You’ll explore how to create global variables inside functions and apply strategies to minimize their use, ensuring your code remains clean and maintainable. After reading this tutorial, you’ll be adept at managing global variables and understanding their impact on your Python code.

By the end of this tutorial, you’ll understand that:

  • A global variable in Python is a variable defined at the module level, accessible throughout the program.
  • Accessing and modifying global variables inside Python functions can be achieved using the global keyword or the globals() function.
  • Python handles name conflicts by searching scopes from local to built-in, potentially causing name shadowing challenges.
  • Creating global variables inside a function is possible using the global keyword or globals(), but it’s generally not recommended.
  • Strategies to avoid global variables include using constants, passing arguments, and employing classes and methods to encapsulate state.

To follow along with this tutorial, you should have a solid understanding of Python programming, including fundamental concepts such as variables, data types, scope, mutability, functions, and classes.

Get Your Code: Click here to download the free sample code that you’ll use to understand when and how to work with global variables in your Python functions.

Take the Quiz: Test your knowledge with our interactive “Using and Creating Global Variables in Your Python Functions” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

Using and Creating Global Variables in Your Python Functions

In this quiz, you'll test your understanding of how to use global variables in Python functions. With this knowledge, you'll be able to share data across an entire program, modify and create global variables within functions, and understand when to avoid using global variables.

Using Global Variables in Python Functions

Global variables are those that you can access and modify from anywhere in your code. In Python, you’ll typically define global variables at the module level. So, the containing module is their scope.

Note: You can also define global variables inside functions, as you’ll learn in the section Creating Global Variables Inside a Function.

Once you’ve defined a global variable, you can use it from within the module itself or from within other modules in your code. You can also use global variables in your functions. However, those cases can get a bit confusing because of differences between accessing and modifying global variables in functions.

To understand these differences, consider that Python can look for variables in four different scopes:

  • The local, or function-level, scope, which exists inside functions
  • The enclosing, or non-local, scope, which appears in nested functions
  • The global scope, which exists at the module level
  • The built-in scope, which is a special scope for Python’s built-in names

To illustrate, say that you’re inside an inner function. In that case, Python can look for names in all four scopes.

When you access a variable in that inner function, Python first looks inside that function. If the variable doesn’t exist there, then Python continues with the enclosing scope of the outer function. If the variable isn’t defined there either, then Python moves to the global and built-in scopes in that order. If Python finds the variable, then you get the value back. Otherwise, you get a NameError:

Python >>> # Global scope >>> def outer_func(): ... # Non-local scope ... def inner_func(): ... # Local scope ... print(some_variable) ... inner_func() ... >>> outer_func() Traceback (most recent call last): ... NameError: name 'some_variable' is not defined >>> some_variable = "Hello from global scope!" >>> outer_func() Hello from global scope! Copied!

When you launch an interactive session, it starts off at the module level of global scope. In this example, you have outer_func(), which defines inner_func() as a nested function. From the perspective of this nested function, its own code block represents the local scope, while the outer_func() code block before the call to inner_func() represents the non-local scope.

If you call outer_func() without defining some_variable in either of your current scopes, then you get a NameError exception because the name isn’t defined.

If you define some_variable in the global scope and then call outer_func(), then you get Hello! on your screen. Internally, Python has searched the local, non-local, and global scopes to find some_variable and print its content. Note that you can define this variable in any of the three scopes, and Python will find it.

This search mechanism makes it possible to use global variables from inside functions. However, while taking advantage of this feature, you can face a few issues. For example, accessing a variable works, but directly modifying a variable doesn’t work:

Python >>> number = 42 >>> def access_number(): ... return number ... >>> access_number() 42 >>> def modify_number(): ... number = 7 ... >>> modify_number() >>> number 42 Copied!

The access_number() function works fine. It looks for number and finds it in the global scope. In contrast, modify_number() doesn’t work as expected. Why doesn’t this function update the value of your global variable, number? The problem is the scope of the variable. You can’t directly modify a variable from a high-level scope like global in a lower-level scope like local.

Internally, Python assumes that any name directly assigned within a function is local to that function. Therefore, the local name, number, shadows its global sibling.

In this sense, global variables behave as read-only names. You can access their values, but you can’t modify them.

Note: The discussion about modifying global variables inside functions revolves around assignment operations rather than in-place mutations of mutable objects. You’ll learn about the effects of mutability on global variables in the section Understanding How Mutability Affects Global Variables.

Read the full article at https://realpython.com/python-use-global-variable-in-function/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: Asynchronous Tasks With Django and Celery

Planet Python - Sun, 2024-12-08 09:00

Integrating Celery with your Django application allows you to offload time-consuming tasks, ensuring smooth user experiences. Celery is a distributed task queue that processes tasks asynchronously, preventing delays in your web app’s response time. By using Celery with Django, you can efficiently manage tasks like sending emails, processing images, and analyzing data without slowing down your application.

Celery works by leveraging a message broker like Redis to communicate between your Django app and Celery workers. This setup enables you to handle tasks outside the main execution thread, improving your app’s performance.

By the end of this tutorial, you’ll understand that:

  • Celery is a distributed task queue that handles tasks outside the main Django app flow.
  • Python’s Celery excels at offloading work and scheduling tasks independently.
  • Using Celery in Django helps maintain app responsiveness during time-intensive tasks.
  • Configuring Celery in Django involves setting up a message broker and defining tasks.
  • A Celery worker performs tasks asynchronously, freeing up the main app.
  • Running a task in Celery requires calling the task with .delay() or .apply_async().
  • Celery is not a message queue but uses a message broker like Redis for communication.

You’re in the right place if you’ve never used Celery in a Django app before, or if you’ve peeked into Celery’s documentation but couldn’t find your way around. You’ll learn how to configure Celery in Django to handle tasks asynchronously, ensuring your application remains responsive and efficient.

To focus this tutorial on the essentials, you’ll integrate Celery into an existing Django app. Go ahead and download the code for that app so that you can follow along:

Get Your Code: Click here to download free the sample code you’ll use to integrate Celery into your Django app.

Python Celery Basics

Celery is a distributed task queue that can collect, record, schedule, and perform tasks outside of your main program.

Note: Celery dropped support for Windows in version 4, so while you may still be able to get it to work on Windows, you’re better off using a different task queue, such as huey or Dramatiq, instead.

In this tutorial, you’ll focus on using Celery on UNIX systems, so if you’re trying to set up a distributed task queue on Windows, then this might not be the right tutorial for you.

To receive tasks from your program and send results to a back end, Celery requires a message broker for communication. Redis and RabbitMQ are two message brokers that developers often use together with Celery.

In this tutorial, you’ll use Redis as the message broker. To challenge yourself, you can stray from the instructions and use RabbitMQ as a message broker instead.

If you want to keep track of the results of your task runs, then you also need to set up a results back end database.

Note: Connecting Celery to a results back end is optional. Once you instruct Celery to run a task, it’ll do its duty whether you keep track of the task result or not.

However, keeping a record of all task results is often helpful, especially if you’re distributing tasks to multiple queues. To persist information about task results, you need a database back end.

You can use many different databases to keep track of Celery task results. In this tutorial, you’ll work with Redis both as a message broker and as a results back end. By using Redis, you limit the dependencies that you need to install because it can take on both roles.

You won’t do any work with the recorded task results in the scope of this tutorial. However, as a next step, you could inspect the results with the Redis command-line interface (CLI) or pull information into a dedicated page in your Django project.

Why Use Celery?

There are two main reasons why most developers want to start using Celery:

  1. Offloading work from your app to distributed processes that can run independently of your app
  2. Scheduling task execution at a specific time, sometimes as recurring events

Celery is an excellent choice for both of these use cases. It defines itself as “a task queue with focus on real-time processing, while also supporting task scheduling” (Source).

Even though both of these functionalities are part of Celery, they’re often addressed separately:

  1. Celery workers are worker processes that run tasks independently from one another and outside the context of your main service.
  2. Celery beat is a scheduler that orchestrates when to run tasks. You can use it to schedule periodic tasks as well.

Celery workers are the backbone of Celery. Even if you aim to schedule recurring tasks using Celery beat, a Celery worker will pick up your instructions and handle them at the scheduled time. What Celery beat adds to the mix is a time-based scheduler for Celery workers.

In this tutorial, you’ll learn how to integrate Celery with Django to perform operations asynchronously from the main execution thread of your app using Celery workers.

You won’t tackle task scheduling with Celery beat in this tutorial, but once you understand the basics of Celery tasks, you’ll be well equipped to set up periodic tasks with Celery beat.

Read the full article at https://realpython.com/asynchronous-tasks-with-django-and-celery/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: Effective Python Testing With pytest

Planet Python - Sun, 2024-12-08 09:00

pytest is a popular testing framework for Python that simplifies the process of writing and executing tests. To start using pytest, install it with pip in a virtual environment. pytest offers several advantages over unittest that ships with Python, such as less boilerplate code, more readable output, and a rich plugin ecosystem.

pytest comes packed with features to boost your productivity. Its fixtures allow for explicit dependency declarations, making tests more understandable and reducing implicit dependencies. Parametrization in pytest helps prevent redundant test code by enabling multiple test cases from a single test function definition. This framework is highly customizable, so you can tailor it to your project’s needs.

By the end of this tutorial, you’ll understand that:

  • Using pytest requires installing it with pip in a virtual environment to set up the pytest command.
  • pytest allows for less code, easier readability, and more features compared to unittest.
  • Managing test dependencies and state with pytest is made efficient through the use of fixtures, which provide explicit dependency declarations.
  • Parametrization in pytest helps avoid redundant test code by allowing multiple test scenarios from a single test function.
  • Assertion introspection in pytest provides detailed information about failures in the test report.

Free Bonus: 5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you’ll need to take your Python skills to the next level.

Take the Quiz: Test your knowledge with our interactive “Effective Testing with Pytest” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

Effective Testing with Pytest

In this quiz, you'll test your understanding of pytest, a Python testing tool. With this knowledge, you'll be able to write more efficient and effective tests, ensuring your code behaves as expected.

How to Install pytest

To follow along with some of the examples in this tutorial, you’ll need to install pytest. As most Python packages, pytest is available on PyPI. You can install it in a virtual environment using pip:

Windows PowerShell PS> python -m venv venv PS> .\venv\Scripts\activate (venv) PS> python -m pip install pytest Copied! Shell $ python -m venv venv $ source venv/bin/activate (venv) $ python -m pip install pytest Copied!

The pytest command will now be available in your installation environment.

What Makes pytest So Useful?

If you’ve written unit tests for your Python code before, then you may have used Python’s built-in unittest module. unittest provides a solid base on which to build your test suite, but it has a few shortcomings.

A number of third-party testing frameworks attempt to address some of the issues with unittest, and pytest has proven to be one of the most popular. pytest is a feature-rich, plugin-based ecosystem for testing your Python code.

If you haven’t had the pleasure of using pytest yet, then you’re in for a treat! Its philosophy and features will make your testing experience more productive and enjoyable. With pytest, common tasks require less code and advanced tasks can be achieved through a variety of time-saving commands and plugins. It’ll even run your existing tests out of the box, including those written with unittest.

As with most frameworks, some development patterns that make sense when you first start using pytest can start causing pains as your test suite grows. This tutorial will help you understand some of the tools pytest provides to keep your testing efficient and effective even as it scales.

Less Boilerplate

Most functional tests follow the Arrange-Act-Assert model:

  1. Arrange, or set up, the conditions for the test
  2. Act by calling some function or method
  3. Assert that some end condition is true

Testing frameworks typically hook into your test’s assertions so that they can provide information when an assertion fails. unittest, for example, provides a number of helpful assertion utilities out of the box. However, even a small set of tests requires a fair amount of boilerplate code.

Imagine you’d like to write a test suite just to make sure that unittest is working properly in your project. You might want to write one test that always passes and one that always fails:

Python test_with_unittest.py from unittest import TestCase class TryTesting(TestCase): def test_always_passes(self): self.assertTrue(True) def test_always_fails(self): self.assertTrue(False) Copied!

You can then run those tests from the command line using the discover option of unittest:

Shell (venv) $ python -m unittest discover F. ====================================================================== FAIL: test_always_fails (test_with_unittest.TryTesting) ---------------------------------------------------------------------- Traceback (most recent call last): File "...\effective-python-testing-with-pytest\test_with_unittest.py", line 10, in test_always_fails self.assertTrue(False) AssertionError: False is not true ---------------------------------------------------------------------- Ran 2 tests in 0.006s FAILED (failures=1) Copied!

As expected, one test passed and one failed. You’ve proven that unittest is working, but look at what you had to do:

Read the full article at https://realpython.com/pytest-python-testing/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: Python Timer Functions: Three Ways to Monitor Your Code

Planet Python - Sun, 2024-12-08 09:00

A timer is a powerful tool for monitoring the performance of your Python code. By using the time.perf_counter() function, you can measure execution time with exceptional precision, making it ideal for benchmarking. Using a timer involves recording timestamps before and after a specific code block and calculating the time difference to determine how long your code took to run.

In this tutorial, you’ll explore three different approaches to implementing timers: classes, decorators, and context managers. Each method offers unique advantages, and you’ll learn when and how to use them to achieve optimal results. Plus, you’ll have a fully functional Python timer that can be applied to any program to measure execution time efficiently.

By the end of this tutorial, you’ll understand that:

  • time.perf_counter() is the best choice for accurate timing in Python due to its high resolution.
  • You can create custom timer classes to encapsulate timing logic and reuse it across multiple parts of your program.
  • Using decorators lets you seamlessly add timing functionality to existing functions without altering their code.
  • You can leverage context managers to neatly measure execution time in specific code blocks, improving both resource management and code clarity.

Along the way, you’ll gain deeper insights into how classes, decorators, and context managers work in Python. As you explore real-world examples, you’ll discover how these concepts can not only help you measure code performance but also enhance your overall Python programming skills.

Decorators Q&A Transcript: Click here to get access to a 25-page chat log from our Python decorators Q&A session in the Real Python Community Slack where we discussed common decorator questions.

Python Timers

First, you’ll take a look at some example code that you’ll use throughout the tutorial. Later, you’ll add a Python timer to this code to monitor its performance. You’ll also learn some of the simplest ways to measure the running time of this example.

Python Timer Functions

If you check out the built-in time module in Python, then you’ll notice several functions that can measure time:

Python 3.7 introduced several new functions, like thread_time(), as well as nanosecond versions of all the functions above, named with an _ns suffix. For example, perf_counter_ns() is the nanosecond version of perf_counter(). You’ll learn more about these functions later. For now, note what the documentation has to say about perf_counter():

Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. (Source)

First, you’ll use perf_counter() to create a Python timer. Later, you’ll compare this with other Python timer functions and learn why perf_counter() is usually the best choice.

Example: Download Tutorials

To better compare the different ways that you can add a Python timer to your code, you’ll apply different Python timer functions to the same code example throughout this tutorial. If you already have code that you’d like to measure, then feel free to follow the examples with that instead.

The example that you’ll use in this tutorial is a short function that uses the realpython-reader package to download the latest tutorials available here on Real Python. To learn more about the Real Python Reader and how it works, check out How to Publish an Open-Source Python Package to PyPI. You can install realpython-reader on your system with pip:

Shell $ python -m pip install realpython-reader Copied!

Then, you can import the package as reader.

You’ll store the example in a file named latest_tutorial.py. The code consists of one function that downloads and prints the latest tutorial from Real Python:

Python latest_tutorial.py 1from reader import feed 2 3def main(): 4 """Download and print the latest tutorial from Real Python""" 5 tutorial = feed.get_article(0) 6 print(tutorial) 7 8if __name__ == "__main__": 9 main() Copied!

realpython-reader handles most of the hard work:

  • Line 1 imports feed from realpython-reader. This module contains functionality for downloading tutorials from the Real Python feed.
  • Line 5 downloads the latest tutorial from Real Python. The number 0 is an offset, where 0 means the most recent tutorial, 1 is the previous tutorial, and so on.
  • Line 7 prints the tutorial to the console.
  • Line 9 calls main() when you run the script.

When you run this example, your output will typically look something like this:

Shell $ python latest_tutorial.py # Python Timer Functions: Three Ways to Monitor Your Code A timer is a powerful tool for monitoring the performance of your Python code. By using the `time.perf_counter()` function, you can measure execution time with exceptional precision, making it ideal for benchmarking. Using a timer involves recording timestamps before and after a specific code block and calculating the time difference to determine how long your code took to run. [ ... ] ## Read the full article at https://realpython.com/python-timer/ » * * * Copied! Read the full article at https://realpython.com/python-timer/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

This Week in KDE Apps: Gear 24.12.0 incoming

Planet KDE - Sun, 2024-12-08 07:50

Welcome to a new issue of "This Week in KDE Apps"! Every week we cover as much as possible of what's happening in the world of KDE apps.

This week, we are adding the final touches to our applications for the KDE Gear 24.12.0 release coming next Thursday. We are also releasing KPhotoAlbum and KGeoTag, now based on Qt6; improving Itinerary's ticket extractor support coverage in central Europe; and continuing our work on Karp, KDE's new PDF editor.

Meanwhile, as part of the 2024 end-of-year fundraiser, you can "Adopt an App" in a symbolic effort to support your favorite KDE app. This week, we are particularly grateful to Stuart Turton for NeoChat; Lukas, Stuart Turton and J. for Merkuro; Andreas Pietzowski, Dia_FIX and Alex Gurenko for Ark; Stuart Turton and Cameron Bosch for Tokodon; Alex Gurenko and Steven Dunbar for Gwenview; Alex Gurenko, Kasimir den Hertog and Pokipan for KWrite; crysknife, Ian Kidd and Felix Urbasik for KRDC; Ian Nicholson for Alligator; Cameron Radmore for ISO Image Writer; Marcel Janik Kimpel and @siriusfox@social.treehouse.systems for KDE Partition Manager; Marton Daniel for Plasma System Monitor; Alessio Adamo for AudioTube; zukigay for Kasts; Anael for Elisa; Stuart Turton and Clément Aubert for Konqueror; Ulrich Palecek, @ddjivan.bsky.social and Andreas Zautner for Discover; Butters for KolourPaint; KjetilS for krfb; and finally fabacam, Michael Klingberg and Gianmarco Gargiulo for GCompris.

Getting back to all that's new in the KDE App scene, let's dig in!

Akonadi Background service for KDE PIM apps

When updating, adding, or removing a tag/category to a calendar event, the update is immediately visible without having to sync again with a remote server (Daniel Vrátil, 24.12.0 — Link).

Alligator RSS feed reader

The "Refresh" action is now also visible on mobile (Mark Penner, 24.12.0 — Link).

Amarok A powerful music player that lets you rediscover your music

A beta release of the upcoming Amarok 3.2 music player is out for testing — see the announcement email.

Amarok devs fixed Ampache version check. Ampache is self-hostable music streamer service server and the version check was broken since Ampache changed their version format, but it works again now (Ian Abbott, Amarok 3.2.0 — Link).

You can also filter a collection by tracks that have tags missing or when tags are empty (Tuomas Nurmi, Amarok 3.2.0 — Link — an 11 year old feature request!).

Arianna EBook reader

Arianna now uses foliate-js instead of epub.js to render EPUB files. foliate-js provides some advantages like no longer requiring to load the whole book into memory, and comes with a better layout engine (Ajay Chauhan, 25.04.0 — Link).

AudioTube YouTube Music app

AudioTube now displays album information in the maximized player view (Kavinu Nethsara, 25.04.0 — Link).

Dolphin Manage your files

Accessibility support in Dolphin was adapted to better work with Orca 47 (Felix Ernst, 25.04.0 — Link), and, continuing with accessibility improvements, after activating a folder in the Dolphin sidebar, the view is now always focused (Felix Ernst, 25.04.0 — Link). Likewise, when clicking on "Open Path" and "Open Path in New Tab" after searching for an item, the view will scroll to the selected item (Akseli Lahtinen, 25.04.0 — Link).

The placeholder message when Samba isn't and can't be installed was improved (Ilya Katsnelson, 25.04.0. and partially backported to 24.12.0 — Link), and the Flatpak version now allows compressing files into an archive (Justin Zobel, 25.04.0 — Link).

Elisa Play local music and listen to online radio

When removing the last track associated with an artist or a music genre, the artist or genre is now removed from the internal database (Jack Hill, 25.04.0 — Link).

Gwenview Image Viewer

We fixed the incorrect numbering in full screen mode for the first image (Pedro Hernandez, 25.04.0 — Link).

KDE Itinerary Digital travel assistant

Volker wrote a recap for the past two months in Itinerary and can read it on his blog. The post includes a report on work unrelated to Itinerary development, but nevertheless important, like the lobbying of DELFI, a cooperation network of all German federal states for public transport.

The "Vehicle Layout" page and the "Journey Details" page were slightly tweaked and use the new unified component to display the name of the train or bus (Carl Schwan, 25.04.0 — Link 1 and link 2).

We also made significant progress on Itinerary's extractors this week, with many new extractors, including:

  • The Colosseum Ticket in Rome (David Pilarcik, Link)
  • The Polish online ticket sale system Droplabs (David Pilarcik, Link)
  • The train booking platform Leo Express (David Pilarcik, Link)
  • The German trade fair, congress, and event ticket sale system, Dimedis Fairmate (Kai Uwe Broulik, Link)
  • Google Maps links (Kai Uwe Broulik, Link)
  • The European Sleeper seat reservations in French (Luca Weiss, Link)
Kaidan Modern chat app for every device

Kaidan will now display a map preview by default when receiving a geo location (Melvin Keskin — Link).

Karp KDE arranger for PDFs

Karp, KDE's new PDF editor, received visual improvements to its main interface (Carl Schwan — Link 1, link 2 and link 3).

And Nicolas setup crash reporting for Karp (Nicolas Fella — Link).

KDE Connect Seamless connection of your devices

We moved the list of devices to the sidebar in an effort to bring the app to parity with the KCM (Darshan Phaldesai, 25.04.0 — Link).

We also added icons to the plugin config list (Leia uwu, 25.04.0 — Link).

For the bluetooth backend, we improved the speed of transferring data between devices (ivan tkachenko, 25.04.0 — Link).

KGeoTag Photo geotagging program

KGeoTag 1.7.0 is out! This release brings Qt6 support to the app. Read the full announcement.

KPhotoAlbum KDE image management software

KPhotoAlbum 6.0.0 is out! This release also brings Qt6 support to the app. Read the full announcement.

Konsole Use the command line interface

It is now possible to resize Konsole's search bar (Eric D'Addario, 25.04.0 — Link), and to search for an open tab by its name (Troy Hoover, 25.04.0 — Link).

Kongress Conference companion

We now display the speaker's name (if available) in the talk info (Volker Krause, 25.04.0 — Link).

Kleopatra Certificate manager and cryptography app

We fixed a crash when the output directory for decrypting doesn't exist (Tobias Fella, 24.12.1 — Link).

KRDC Connect with RDP or VNC to another computer

We fixed the "Grab Keys" feature on Wayland when switching from and to full screen. Additionally the "Grab Keys" feature, now also correctly forwards every shortcut to the remote applications (Fabio Bas, 25.04.0 — Link 1 and link 2).

We also fixed building KRDC on Haiku (Luc Schrijvers, 24.12.1 — Link).

NeoChat Chat on Matrix

You can now sort rooms in the sidebar based on their most recent activity instead of by unread notifications (Soumyadeep Ghosh, 25.04.0 — Link), and added a "Copy Link Address" context menu when clicking on a message (Kai Uwe Broulik, 25.04.0 — Link).

We fixed the capitalization of the account dialog as well as many of NeoChat's settings pages (Joshua Goins, 25.04.0 — Link), and removed device details from the device display name, as this could leak sensitive information (Tobias Fella, 24.12.0 — Link).

Okular View and annotate documents

When creating a new signature, Okular will automatically pick a font size depending on the available size instead of using a hardcoded size. This allows you to make signatures much smaller than before (Nicolas Fella, 25.04.0 — Link). This work was sponsored by the Technische Universität Dresden.

PlasmaTube Watch YouTube videos

We improved the support for Piped, an alternative privacy-friendly YouTube frontend, in PlasmaTube, as we have improved the parsing of its media format information (Alexey Andreyev, 25.04.0 — Link).

Tokodon Browse the Fediverse

The Mastodon client used when posting on Mastodon is now displayed as a Kirigami.Chip element (Joshua Goins, 25.04.0 — Link).

We also fixed the support for GoToSocial (snow flurry, 24.12.0 — Link 1 and link 2), and added prelimary support for Iceshrimp (Joshua Goins, 24.12.0 — Link)).

Spectacle Screenshot Capture Utility

Spectacle can now export to an animated WebP or a GIF (Noah Davis, 25.04.0 — Link).

…And Everything Else

This blog only covers the tip of the iceberg! If you’re hungry for more, check out Nate's blog about Plasma and be sure not to miss his This Week in Plasma series, where every Saturday he covers all the work being put into KDE's Plasma desktop environment.

For a complete overview of what's going on, visit KDE's Planet, where you can find all KDE news unfiltered directly from our contributors.

Get Involved

The KDE organization has become important in the world, and your time and contributions have helped us get there. As we grow, we're going to need your support for KDE to become sustainable.

You can help KDE by becoming an active community member and getting involved. Each contributor makes a huge difference in KDE — you are not a number or a cog in a machine! You don’t have to be a programmer either. There are many things you can do: you can help hunt and confirm bugs, even maybe solve them; contribute designs for wallpapers, web pages, icons and app interfaces; translate messages and menu items into your own language; promote KDE in your local community; and a ton more things.

You can also help us by donating. Any monetary contribution, however small, will help us cover operational costs, salaries, travel expenses for contributors and in general just keep KDE bringing Free Software to the world.

To get your application mentioned here, please ping us in invent or in Matrix.

Thanks to Michael Mischurow and Tobias Fella for proofreading this post.

Categories: FLOSS Project Planets

Paulo Henrique de Lima Santana: Bits from MiniDebConf Toulouse 2024

Planet Debian - Sun, 2024-12-08 05:00
Intro

I always find it amazing the opportunities I have thanks to my contributions to the Debian Project. I am happy to receive this recognition through the help I receive with travel to attend events in other countries.

This year, two MiniDebConfs were scheduled for the second half of the year in Europe: the traditional edition in Cambridge in UK and a new edition in Toulouse in France. After weighing the difficulties and advantages that I would have to attend one of them, I decided to choose Toulouse, mainly because it was cheaper and because it was in November, giving me more time to plan the trip. I contacted the current DPL Andreas Tille explaining my desire to attend the event and he kindly approved my request for Debian to pay for the tickets. Thanks again to Andreas!

MiniDebConf Toulouse 2024 was held in November 16th and 17th (Saturday and Sunday) and took place in one of the rooms of a traditional Free Software event in the city named Capitole du Libre. Before MiniDebConf, the team organized a MiniDebCamp in November 14th and 15th at a coworking space.

The whole experience promised to be incredible, and it was! From visiting a city in France for the first time, to attending a local Free Software event, and sharing four days with people from the Debian community from various countries.

Travel and the city

My plan was to leave Belo Horizonte on Monday, pass through São Paulo, and arrive in Toulouse on Tuesday night. I was going to spend the whole of Wednesday walking around the city and then participate in the MiniDebCamp on Thursday.

But the flight that was supposed to leave São Paulo in the early hours of Monday to Tuesday was cancelled due to a problem with the airplane and I had spent all Tuesday waiting. I was rebooked on another flight that left in the evening and arrived in Toulouse on Wednesday afternoon. Even though I was very tired from the trip, I still took advantage of the end of the day to walk around the city. But it was a shame to have lost an entire day of sightseeing.

On Thursday I left early in the morning to walk around a little more before going to the MiniDebCamp venue. I walked around a lot and saw several tourist attractions. The city is really very beautiful, as they say, especially the houses and buildings made of pink bricks. I was impressed by the narrow and winding streets; at one point it seemed like I was walking through a maze. I arrived to a corner and there would be 5 streets crossing in different directions.

The riverbank that runs through the city is very beautiful and people spend their evenings there just hanging out. There was a lot of history around there.

I stayed in an airbnb 25 minutes walking from the coworking space and only 10 minutes from the event venue. It was a very spacious apartment that was much cheaper than a hotel.



MiniDebCamp

I arrived at the coworking space where the MiniDebCamp was being held and met up with several friends. I also met some new people, talked about the translation work we do in Brazil, and other topics.

We already knew that the organization would pay for lunch for everyone during the two days of MiniDebCamp, and at a certain point they told us that we could go to the room (which was downstairs from the coworking space) to have lunch. They set up a table with quiches, breads, charcuterie and LOTS of cheese :-) There were several types of cheese and they were all very good. I just found it a little strange because I’m not used to having cheese for lunch :-)



In the evening, we went as a group to dinner at a restaurant in front of the Capitolium, the city’s main tourist attraction.

On the second day, in the morning, I walked around the city a bit more, then went to the coworking space and had another incredible cheese table for lunch.

Video Team

One of my ideas for going to Toulouse was to be able to help the video team in setting up the equipment for broadcasting and recording the talks. I wanted to follow this work from the beginning and learn some details, something I can’t do before the DebConfs because I always arrive after the people have already set up the infrastructure. And later reproduce this work in the MiniDebConfs in Brazil, such as the one in Maceió that is already scheduled for May 1-4, 2025.

As I had agreed with the people from the video team that I would help set up the equipment, on Friday night we went to the University and stayed in the room working. I asked several questions about what they were doing, about the equipment, and I was able to clear up several doubts. Over the next two days I was handling one of the cameras during the talks. And on Sunday night I helped put everything away.

Thanks to olasd, tumbleweed and ivodd for their guidance and patience.

The event in general

There was also a meeting with some members of the publicity team who were there with the DPL. We went to a cafeteria and talked mainly about areas that could be improved in the team.

The talks at MiniDebConf were very good and the recordings are also available here.

I ended up not watching any of the talks from the general schedule at Capitole du Libre because they were in French. It’s always great to see free software events abroad to learn how they are done there and to bring some of those experiences to our events.

I hope that MiniDebConf in Toulouse will continue to take place every year, or that the French community will hold the next edition in another city and I will be able to join again :-) If everything goes well, in July next year I will return to France to join DebConf25 in Brest.

More photos

Categories: FLOSS Project Planets

LostCarPark Drupal Blog: Drupal Advent Calendar day 8 - SEO

Planet Drupal - Sun, 2024-12-08 04:00
Drupal Advent Calendar day 8 - SEO james Sun, 12/08/2024 - 09:00

Today we are looking at another aspect of Drupal Starshot that may not generate a lot of excitement, but will make it a lot easier for the average marketer or Drupal site builder to make their site perform well and be easy to find.

Search Engine Optimization (SEO) has often been treated as something of a dark art. Any number of self-proclaimed masters of this art will promise to take your site to new levels, their ability to deliver varies greatly.

Drupal CMS aims to provide ready-to-use tools to help improve search engine performance, and “SEO Tools” is one of the “goals” offered during the…

Tags
Categories: FLOSS Project Planets

Russ Allbery: Review: Why Buildings Fall Down

Planet Debian - Sat, 2024-12-07 23:04

Review: Why Buildings Fall Down, by Matthys Levy & Mario Salvadori

Illustrator: Kevin Woest Publisher: W.W. Norton Copyright: 1992 Printing: 1994 ISBN: 0-393-31152-X Format: Trade paperback Pages: 314

Why Buildings Fall Down is a non-fiction survey of the causes of structure collapses, along with some related topics. It is a sequel of sorts to Why Buildings Stand Up by Mario Salvadori, which I have not read. Salvadori was, at the time of writing, Professor Emeritus of Architecture at Columbia University (he died in 1997). Levy is an award-winning architectural engineer, and both authors were principals at the structural engineering firm Weidlinger Associates. There is a revised and updated 2002 edition, but this review is of the original 1992 edition.

This is one of those reviews that comes with a small snapshot of how my brain works. I got fascinated by the analysis of the collapse of Champlain Towers South in Surfside, Florida in 2021, thanks largely to a random YouTube series on the tiny channel of a structural engineer. Somewhere in there (I don't remember where, possibly from that channel, possibly not) I saw a recommendation for this book and grabbed a used copy in 2022 with the intent of reading it while my interest was piqued. The book arrived, I didn't read it right away, I got distracted by other things, and it migrated to my shelves and sat there until I picked it up on an "I haven't read nonfiction in a while" whim.

Two years is a pretty short time frame for a book to sit on my shelf waiting for me to notice it again. The number of books that have been doing that for several decades is, uh, not small.

Why Buildings Fall Down is a non-technical survey of structure failures. These are mostly buildings, but also include dams, bridges, and other structures. It's divided into 18 fairly short chapters, and the discussion of each disaster is brisk and to the point. Most of the structures discussed are relatively recent, but the authors talk about the Meidum Pyramid, the Parthenon (in the chapter on intentional destruction by humans), and the Pavia Civic Tower (in the chapter about building death from old age). If you are someone who has already been down the structural failure rabbit hole, you will find chapters on the expected disasters like the Tacoma Narrows Bridge collapse and the Hyatt Regency walkway collapse, but there are a lot of incidents here, including a short but interesting discussion of the Leaning Tower of Pisa in the chapter on problems caused by soil properties.

What you're going to get, in other words, is a tour of ways in which structures can fail, which is precisely what was promised by the title. This wasn't quite what I was expecting, but now I'm not sure why I was expecting something different. There is no real unifying theme here; sometimes the failure was an oversight, sometimes it was a bad design, sometimes it was a last-minute change, and sometimes it was something unanticipated. There are a lot of factors involved in structure design and any of them can fail. The closest there is to a common pattern is a lack of redundancy and sufficient safety factors, but that lack of redundancy was generally not deliberate and therefore this is not a guide to preventing a collapse. The result is a book that feels a bit like a grab-bag of structural trivia that is individually interesting but only occasionally memorable.

The writing style I suspect will be a matter of taste, but once I got used to it, I rather enjoyed it. In a co-written book, it's hard to separate the voices of the authors, but Salvadori wrote most of the chapter on the law in the first person and he's clearly a character. (That chapter is largely the story of two trials he testified in, which, from his account, involved him verbally fencing with lawyers who attempted to claim his degrees from the University of Rome didn't count as real degrees.) If this translates to his speaking style, I suspect he was a popular lecturer at Columbia.

The explanations of the structural failures are concise and relatively clear, although even with Kevin Woest's diagrams, it's hard to capture the stresses and movement in a written description. (I've found from watching YouTube videos that animations, or even annotations drawn while someone is talking, help a lot.) The framing discussion, well, sometimes that is bombastic in a way that I found amusing:

But we, children of a different era, do not want our lives to be enclosed, to be shielded from the mystery. We are eager to participate in it, to gather with our brothers and sisters in a community of thought that will lift us above the mundane. We need to be together in sorrow and in joy. Thus we rarely build monolithic monuments. Instead, we build domes.

It helps that passages like this are always short and thus don't wear out their welcome. My favorite line in the whole book is a throwaway sentence in a discussion of building failures due to explosions:

With a similar approach, it can be estimated that the chance of an explosion like that at Forty-fifth Street was at most one in thirty million, and probably much less. But this is why life is dangerous and always ends in death.

Going hard, structural engineering book!

It's often appealing to learn about things from their failures because the failures are inherently more dramatic and thus more interesting, but if you were hoping for an introduction to structural engineering, this is probably not the book you want. There is an excellent and surprisingly engaging appendix that covers the basics of structural analysis in 45 pages, but you would probably be better off with Why Buildings Stand Up or another architecture or structural engineering textbook (or maybe a video course). The problem with learning by failure case study is that all the case studies tend to blend together, despite the authors' engaging prose, and nearly every collapse introduces a new structural element with new properties and new failure modes and only the briefest of explanations. This book might make you a slightly more informed consumer of the news, but for most readers I suspect it will be a collection of forgettable trivia told in an occasionally entertaining style.

I think the book I wanted to read was something that went deeper into the process of forensic engineering, not just the outcomes. It's interesting to know what the cause of a failure was, but I'm more interested in how one goes about investigating a failure. What is the process, how do you organize the investigation, and how does the legal system around engineering failures work? There are tidbits and asides here, but this book is primarily focused on the structural analysis and elides most of the work done to arrive at those conclusions.

That said, I was entertained. Why Buildings Fall Down is a bit dated — the opening chapter on airplanes hitting buildings reads much differently now than when it was written in 1992, and I'm sure it was updated in the 2002 edition — but it succeeds in being clear without being soulless or sounding like a textbook. I appreciate an occasional rant about nuclear weapons in a book about architecture. I'm not sure I really recommend this, but I had a good time with it.

Also, I'm now looking for opportunities to say "this is why life is dangerous and always ends in death," so there is that.

Rating: 6 out of 10

Categories: FLOSS Project Planets

Dominique Dumont: New cme command to update Debian Standards-Version field

Planet Debian - Sat, 2024-12-07 12:52

Hi

While updating my Debian package, I often have to update a field from debian/control file.

This field is named Standards-Version and it declares which version of Debian policy the package complies to. When updating this field, one must follow the upgrading checklist.

That being said, I maintain a lot of similar package and I often have to update this Standards-Version field.

This field can be updated manually with cme fix dpkg (see Managing Debian packages with cme). But this command may make other changes and does not commit the result.

So I’ve created a new update-standards-version cme script that:

  • udpate Standards-Version field
  • commit the changed

For instance:

$ cme run update-standards-version Reading package lists... Done Building dependency tree... Done Reading state information... Done Connecting to api.ftp-master.debian.org to check 31 package versions. Please wait... Got info from api.ftp-master.debian.org for 31 packages. Warning in 'source Standards-Version': Current standards version is '4.7.0'. Please read https://www.debian.org/doc/debian-policy/upgrading-checklist.html for the changes that may be needed on your package to upgrade it from standard version '4.6.2' to '4.7.0'. Offending value: '4.6.2' Changes applied to dpkg-control configuration: - source Standards-Version: '4.6.2' -> '4.7.0' [master 552862c1] control: declare compliance with Debian policy 4.7.0 1 file changed, 1 insertion(+), 1 deletion(-)

Here’s the generated commit. Note that the generated log mentions the new policy version:

domi@ylum:~/private/debian-dev/perl-stuff/libconfig-model-perl$ git show commit 552862c1f24479b1c0c8c35a6289557f65e8ff3b (HEAD -> master) Author: Dominique Dumont <dod[at]debian.org> Date: Sat Dec 7 19:06:14 2024 +0100 control: declare compliance with Debian policy 4.7.0 diff --git a/debian/control b/debian/control index cdb41dc0..e888012e 100644 --- a/debian/control +++ b/debian/control @@ -48,7 +48,7 @@ Build-Depends-Indep: dh-sequence-bash-completion, libtext-levenshtein-damerau-perl, libyaml-tiny-perl, po-debconf -Standards-Version: 4.6.2 +Standards-Version: 4.7.0 Vcs-Browser: https://salsa.debian.org/perl-team/modules/packages/libconfig-model-perl Vcs-Git: https://salsa.debian.org/perl-team/modules/packages/libconfig-model-perl.git Homepage: https://github.com/dod38fr/config-model/wiki

Notes:

  • this script can run only if there’s not pending change. Please commit or stash these changes before running this script.
  • this script requires:
    • cme >= 1.041
    • libconfig-model-perl >= 2.155
    • libconfig-model-dpkg-perl >= 3.006

I hope this will be useful to all my fellow Debian developers to reduce the boring parts of packaging activities.

All the best

Categories: FLOSS Project Planets

Freelock Blog: Remind customers of abandoned carts

Planet Drupal - Sat, 2024-12-07 10:00
Remind customers of abandoned carts Anonymous (not verified) Sat, 12/07/2024 - 07:00 Tags Analytics ECA Customer Service Drupal Planet

Sometimes a simple reminder can spur a sale. If you have repeat customers that log into your commerce site, you may be able to remind them if they did not complete a checkout.

Categories: FLOSS Project Planets

The Drop Times: DrupalCon Singapore 2024: Spotlight on Sponsors Driving Innovation and Community Growth

Planet Drupal - Sat, 2024-12-07 09:41
This is a chance to engage with leading developers, project managers, and decision-makers who are shaping Drupal's future. Beyond the exposure, sponsors gain valuable insights and opportunities to build lasting relationships within the community.
Categories: FLOSS Project Planets

Real Python: Linear Regression in Python

Planet Python - Sat, 2024-12-07 09:00

Linear regression is a foundational statistical tool for modeling the relationship between a dependent variable and one or more independent variables. It’s widely used in data science and machine learning to predict outcomes and understand relationships between variables. In Python, implementing linear regression can be straightforward with the help of third-party libraries such as scikit-learn and statsmodels.

By the end of this tutorial, you’ll understand that:

  • Linear regression is a statistical method for modeling the relationship between a dependent variable and one or more independent variables by fitting a linear equation.
  • Implementing linear regression in Python involves using libraries like scikit-learn and statsmodels to fit models and make predictions.
  • The formula for linear regression is 𝑦 = 𝛽₀ + 𝛽₁𝑥₁ + ⋯ + 𝛽ᵣ𝑥ᵣ + 𝜀, representing the linear relationship between variables.
  • Simple linear regression involves one independent variable, whereas multiple linear regression involves two or more.
  • The scikit-learn library provides a convenient and efficient interface for performing linear regression in Python.

To implement linear regression in Python, you typically follow a five-step process: import necessary packages, provide and transform data, create and fit a regression model, evaluate the results, and make predictions. This approach allows you to perform both simple and multiple linear regressions, as well as polynomial regression, using Python’s robust ecosystem of scientific libraries.

Free Bonus: Click here to get access to a free NumPy Resources Guide that points you to the best tutorials, videos, and books for improving your NumPy skills.

Take the Quiz: Test your knowledge with our interactive “Linear Regression in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

Linear Regression in Python

In this quiz, you'll test your knowledge of linear regression in Python. Linear regression is one of the fundamental statistical and machine learning techniques, and Python is a popular choice for machine learning.

Regression

Regression analysis is one of the most important fields in statistics and machine learning. There are many regression methods available. Linear regression is one of them.

What Is Regression?

Regression searches for relationships among variables. For example, you can observe several employees of some company and try to understand how their salaries depend on their features, such as experience, education level, role, city of employment, and so on.

This is a regression problem where data related to each employee represents one observation. The presumption is that the experience, education, role, and city are the independent features, while the salary depends on them.

Similarly, you can try to establish the mathematical dependence of housing prices on area, number of bedrooms, distance to the city center, and so on.

Generally, in regression analysis, you consider some phenomenon of interest and have a number of observations. Each observation has two or more features. Following the assumption that at least one of the features depends on the others, you try to establish a relation among them.

In other words, you need to find a function that maps some features or variables to others sufficiently well.

The dependent features are called the dependent variables, outputs, or responses. The independent features are called the independent variables, inputs, regressors, or predictors.

Regression problems usually have one continuous and unbounded dependent variable. The inputs, however, can be continuous, discrete, or even categorical data such as gender, nationality, or brand.

It’s a common practice to denote the outputs with 𝑦 and the inputs with 𝑥. If there are two or more independent variables, then they can be represented as the vector 𝐱 = (𝑥₁, …, 𝑥ᵣ), where 𝑟 is the number of inputs.

When Do You Need Regression?

Typically, you need regression to answer whether and how some phenomenon influences the other or how several variables are related. For example, you can use it to determine if and to what extent experience or gender impacts salaries.

Regression is also useful when you want to forecast a response using a new set of predictors. For example, you could try to predict electricity consumption of a household for the next hour given the outdoor temperature, time of day, and number of residents in that household.

Regression is used in many different fields, including economics, computer science, and the social sciences. Its importance rises every day with the availability of large amounts of data and increased awareness of the practical value of data.

Linear Regression

Linear regression is probably one of the most important and widely used regression techniques. It’s among the simplest regression methods. One of its main advantages is the ease of interpreting results.

Problem Formulation

When implementing linear regression of some dependent variable 𝑦 on the set of independent variables 𝐱 = (𝑥₁, …, 𝑥ᵣ), where 𝑟 is the number of predictors, you assume a linear relationship between 𝑦 and 𝐱: 𝑦 = 𝛽₀ + 𝛽₁𝑥₁ + ⋯ + 𝛽ᵣ𝑥ᵣ + 𝜀. This equation is the regression equation. 𝛽₀, 𝛽₁, …, 𝛽ᵣ are the regression coefficients, and 𝜀 is the random error.

Read the full article at https://realpython.com/linear-regression-in-python/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: Socket Programming in Python (Guide)

Planet Python - Sat, 2024-12-07 09:00

Socket programming is essential for network communication, enabling data exchange across different devices. In Python, sockets allow for inter-process communication (IPC) over networks. This tutorial provides a comprehensive guide on creating socket servers and clients, handling multiple connections, and managing errors in Python’s socket module.

By the end of this tutorial, you’ll understand that:

  • A socket in Python is an endpoint for sending or receiving data across a network using the socket API.
  • Socket programming in Python involves using sockets to establish communication between a server and clients over a network.
  • A simple echo server in Python can be created using sockets to listen for client connections and echo back received messages.
  • Handling multiple clients with Python sockets can be achieved using non-blocking sockets and the selectors module for concurrent connections.
  • Connection errors in socket programs in Python can be managed by implementing error handling and using exceptions like OSError.

Along the way, you’ll learn about the main functions and methods in Python’s socket module that let you write your own client-server applications based on TCP sockets. You’ll learn how to reliably send messages and data between endpoints and handle multiple connections simultaneously.

Networking and sockets are large subjects. Literal volumes have been written about them. If you’re new to sockets or networking, it’s completely normal if you feel overwhelmed with all of the terms and pieces. To get the most out of this tutorial, it’s best to download the source code and have it on hand for reference while reading:

Get Your Code: Click here to get the free sample code you’ll use to learn about socket programming in Python.

Take the Quiz: Test your knowledge with our interactive “Socket Programming in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

Socket Programming in Python

In this quiz, you'll test your understanding of Python sockets. With this knowledge, you'll be able to create your own client-server applications, handle multiple connections simultaneously, and send messages and data between endpoints.

Historical Background

Sockets have a long history. Their use originated with ARPANET in 1971 and later became an API in the Berkeley Software Distribution (BSD) operating system released in 1983 called Berkeley sockets.

When the Internet took off in the 1990s with the World Wide Web, so did network programming. Web servers and browsers weren’t the only applications taking advantage of newly connected networks and using sockets. Client-server applications of all types and sizes came into widespread use.

Today, although the underlying protocols used by the socket API have evolved over the years, and new ones have developed, the low-level API has remained the same.

The most common type of socket applications are client-server applications, where one side acts as the server and waits for connections from clients. This is the type of application that you’ll be creating in this tutorial. More specifically, you’ll focus on the socket API for Internet sockets, sometimes called Berkeley or BSD sockets. There are also Unix domain sockets, which can only be used to communicate between processes on the same host.

Python Socket API Overview

Python’s socket module provides an interface to the Berkeley sockets API. This is the module that you’ll use in this tutorial.

The primary socket API functions and methods in this module are:

  • socket()
  • .bind()
  • .listen()
  • .accept()
  • .connect()
  • .connect_ex()
  • .send()
  • .recv()
  • .close()

Python provides a convenient and consistent API that maps directly to system calls, their C counterparts. In the next section, you’ll learn how these are used together.

As part of its standard library, Python also has classes that make using these low-level socket functions easier. Although it’s not covered in this tutorial, you can check out the socketserver module, a framework for network servers. There are also many modules available that implement higher-level Internet protocols like HTTP and SMTP. For an overview, see Internet Protocols and Support.

TCP Sockets

You’re going to create a socket object using socket.socket(), specifying the socket type as socket.SOCK_STREAM. When you do that, the default protocol that’s used is the Transmission Control Protocol (TCP). This is a good default and probably what you want.

Why should you use TCP? The Transmission Control Protocol (TCP):

  • Is reliable: Packets dropped in the network are detected and retransmitted by the sender.
  • Has in-order data delivery: Data is read by your application in the order it was written by the sender.

In contrast, User Datagram Protocol (UDP) sockets created with socket.SOCK_DGRAM aren’t reliable, and data read by the receiver can be out-of-order from the sender’s writes.

Why is this important? Networks are a best-effort delivery system. There’s no guarantee that your data will reach its destination or that you’ll receive what’s been sent to you.

Network devices, such as routers and switches, have finite bandwidth available and come with their own inherent system limitations. They have CPUs, memory, buses, and interface packet buffers, just like your clients and servers. TCP relieves you from having to worry about packet loss, out-of-order data arrival, and other pitfalls that invariably happen when you’re communicating across a network.

Read the full article at https://realpython.com/python-sockets/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: How to Round Numbers in Python

Planet Python - Sat, 2024-12-07 09:00

Rounding numbers in Python is an essential task, especially when dealing with data precision. Python’s built-in round() function uses the rounding half to even strategy, which rounds numbers like 2.5 to 2 and 3.5 to 4. This method helps minimize rounding bias in datasets. To round numbers to specific decimal places, you can use the round() function with a second argument specifying the number of decimals.

For more advanced rounding strategies, you can explore Python’s decimal module or use NumPy and pandas for data science applications. NumPy arrays and pandas DataFrames offer methods for rounding numbers efficiently. In NumPy, you can use functions like np.round(), np.ceil(), np.floor(), and np.trunc() to apply different rounding strategies. For pandas, the df.round() method allows rounding of entire DataFrames or specific columns.

By the end of this tutorial, you’ll understand that:

  • Python uses the rounding half to even strategy, where ties round to the nearest even number.
  • Python’s default rounding strategy minimizes rounding bias in large datasets.
  • You can round numbers to specific decimal places using Python’s round() function with a second argument.
  • Different rounding strategies can be applied using Python’s decimal module or custom functions for precision control.
  • NumPy and pandas provide methods for rounding numbers in arrays and DataFrames, offering flexibility in data manipulation.

You won’t get a treatise on numeric precision in computing, although you’ll touch briefly on the subject. Only a familiarity with the fundamentals of Python is necessary, and the math should feel familiar if you’ve had high school algebra.

You’ll start by looking at Python’s built-in rounding mechanism.

Take the Quiz: Test your knowledge with our interactive “Rounding Numbers in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

Rounding Numbers in Python

Test your knowledge of rounding numbers in Python.

Get Your Code: Click here to download the free sample code you’ll use to learn about rounding numbers in Python.

Python’s Built-in round() Function

Python has a built-in round() function that takes two numeric arguments, n and ndigits, and returns the number n rounded to ndigits. The ndigits argument defaults to zero, so leaving it out results in a number rounded to an integer. As you’ll see, round() may not work quite as you expect.

The way most people are taught to round a number goes something like this:

  • Round the number n to p decimal places by first shifting the decimal point in n by p places. To do that, multiply n by 10ᵖ (10 raised to the p power) to get a new number, m.

  • Then look at the digit d in the first decimal place of m. If d is less than 5, round m down to the nearest integer. Otherwise, round m up.

  • Finally, shift the decimal point back p places by dividing m by 10ᵖ.

It’s an algorithm! For example, the number 2.5 rounded to the nearest whole number is 3. The number 1.64 rounded to one decimal place is 1.6.

Now open up an interpreter session and round 2.5 to the nearest whole number using Python’s built-in round() function:

Python >>> round(2.5) 2 Copied!

Gasp!

Check out how round() handles the number 1.5:

Python >>> round(1.5) 2 Copied!

So, round() rounds 1.5 up to 2, and 2.5 down to 2!

Before you go raising an issue on the Python bug tracker, rest assured you that round(2.5) is supposed to return 2. There’s a good reason why round() behaves the way it does.

In this tutorial, you’ll learn that there are more ways to round a number than you might expect, each with unique advantages and disadvantages. round() behaves according to a particular rounding strategy—which may or may not be the one you need for a given situation.

You might be wondering, Can the way I round numbers really have that much of an impact? Next up, take a look at just how extreme the effects of rounding can be.

How Much Impact Can Rounding Have?

Suppose you have an incredibly lucky day and find $100 on the ground. Rather than spending all your money at once, you decide to play it smart and invest your money by buying some shares of different stocks.

The value of a stock depends on supply and demand. The more people there are who want to buy a stock, the more value that stock has, and vice versa. In high-volume stock markets, the value of a particular stock can fluctuate on a second-by-second basis.

Read the full article at https://realpython.com/python-rounding/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: Python GUI Programming With Tkinter

Planet Python - Sat, 2024-12-07 09:00

Tkinter is Python’s standard GUI framework, making it convenient for developing graphical user interfaces. As a cross-platform library, Tkinter ensures your applications appear native across Windows, macOS, and Linux. Despite criticisms of its outdated appearance, Tkinter remains a practical choice for quickly creating functional and cross-platform GUI applications.

By the end of this tutorial, you’ll understand that:

  • GUI refers to graphical user interfaces, and Tkinter is Python’s built-in library for creating them.
  • Tkinter is included with most Python installations, so separate installation is often unnecessary.
  • Tkinter is still a relevant choice for building simple, cross-platform GUI applications.
  • Widgets in a Tkinter application can be arranged using geometry managers like .pack(), .place(), and .grid().
  • Interactive GUI applications with Tkinter are created by binding events, such as button clicks, to Python functions.

You’ll cover getting started with Tkinter, managing widgets, and creating interactive applications. Once you’ve mastered these skills by working through the exercises at the end of each section, you’ll tie everything together by building two applications. The first is a temperature converter, and the second is a text editor. It’s time to dive right in and learn how to build an application with Tkinter!

Note: This tutorial is adapted from the chapter “Graphical User Interfaces” of Python Basics: A Practical Introduction to Python 3.

The book uses Python’s built-in IDLE editor to create and edit Python files and interact with the Python shell. In this tutorial, references to IDLE have been removed in favor of more general language.

The bulk of the material in this tutorial has been left unchanged, and you should have no problems running the example code from the editor and environment of your choice.

Free Bonus: 5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you’ll need to take your Python skills to the next level.

Take the Quiz: Test your knowledge with our interactive “Python GUI Programming With Tkinter” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

Python GUI Programming With Tkinter

In this quiz, you'll test your understanding of Python GUI Programming With Tkinter, the de facto Python GUI framework. Check your knowledge of GUI programming concepts such as widgets, geometry managers, and event handlers.

Building Your First Python GUI Application With Tkinter

The foundational element of a Tkinter GUI is the window. Windows are the containers in which all other GUI elements live. These other GUI elements, such as text boxes, labels, and buttons, are known as widgets. Widgets are contained inside of windows.

First, create a window that contains a single widget. Start up a new Python shell session and follow along!

Note: The code examples in this tutorial have all been tested on Windows, macOS, and Ubuntu Linux 20.04 with Python version 3.10.

If you’ve installed Python with the official installers available for Windows and macOS from python.org, then you should have no problem running the sample code. You can safely skip the rest of this note and continue with the tutorial!

If you haven’t installed Python with the official installers, or there’s no official distribution for your system, then here are some tips for getting up and going.

Python on macOS with Homebrew:

The Python distribution for macOS available on Homebrew doesn’t come bundled with the Tcl/Tk dependency required by Tkinter. The default system version is used instead. This version may be outdated and prevent you from importing the Tkinter module. To avoid this problem, use the official macOS installer.

Ubuntu Linux 20.04:

To conserve memory space, the default version of the Python interpreter that comes pre-installed on Ubuntu Linux 20.04 has no support for Tkinter. However, if you want to continue using the Python interpreter bundled with your operating system, then install the following package:

Shell $ sudo apt-get install python3-tk Copied!

This installs the Python GUI Tkinter module.

Other Linux Flavors:

If you’re unable to get a working Python installation on your flavor of Linux, then you can build Python with the correct version of Tcl/Tk from the source code. For a step-by-step walk-through of this process, check out the Python 3 Installation & Setup Guide. You may also try using pyenv to manage multiple Python versions.

With your Python shell open, the first thing you need to do is import the Python GUI Tkinter module:

Python >>> import tkinter as tk Copied!

A window is an instance of Tkinter’s Tk class. Go ahead and create a new window and assign it to the variable window:

Python >>> window = tk.Tk() Copied!

When you execute the above code, a new window pops up on your screen. How it looks depends on your operating system:

Throughout the rest of this tutorial, you’ll see Windows screenshots.

Adding a Widget

Now that you have a window, you can add a widget. Use the tk.Label class to add some text to a window. Create a Label widget with the text "Hello, Tkinter" and assign it to a variable called greeting:

Python >>> greeting = tk.Label(text="Hello, Tkinter") Copied!

The window you created earlier doesn’t change. You just created a Label widget, but you haven’t added it to the window yet. There are several ways to add widgets to a window. Right now, you can use the Label widget’s .pack() method:

Python >>> greeting.pack() Copied!

The window now looks like this:

Read the full article at https://realpython.com/python-gui-tkinter/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Real Python: When to Use a List Comprehension in Python

Planet Python - Sat, 2024-12-07 09:00

List comprehensions in Python provide a concise way to create lists by embedding a loop and optional conditional logic in a single line. You use a list comprehension to transform and filter elements from an iterable efficiently. It allows you to replace complex loops and map() functions with more readable and often faster expressions. By understanding list comprehensions, you can optimize your code for better performance and clarity.

You can add conditional logic to a list comprehension in Python by appending an if statement to the end of the expression. This allows you to filter elements based on a condition, effectively replacing the need for filter() in many cases. Additionally, you can use conditional expressions at the beginning to choose between different outcomes, enhancing the versatility of your list comprehensions.

By the end of this tutorial, you’ll understand that:

  • A list comprehension in Python is a tool for creating lists by iterating over an iterable and optionally applying a condition.
  • You should use list comprehensions instead of loops when you want concise, readable code that performs transformations or filtering.
  • You add conditional logic to a list comprehension by including an if statement within the comprehension.
  • A list comprehension can be faster than a for loop because it’s optimized for performance by Python’s internal mechanisms.
  • A Python list comprehension is not lazy—it generates and stores the entire list in memory eagerly.
  • The difference between list comprehensions and map() is that the former creates a list, while the latter returns a map object, which is iterable.
  • To optimize performance with list comprehensions, use them for small to medium-sized lists and profile different approaches to choose the fastest one.

In this tutorial, you’ll explore how to leverage list comprehensions to simplify your code. You’ll also gain an understanding of the trade-offs that come with using them so that you can determine when other approaches are preferable.

Get Your Code: Click here to download the free code that shows you how and when to use list comprehensions in Python.

Take the Quiz: Test your knowledge with our interactive “When to Use a List Comprehension in Python” quiz. You’ll receive a score upon completion to help you track your learning progress:

Interactive Quiz

When to Use a List Comprehension in Python

In this quiz, you'll test your understanding of Python list comprehensions. You'll revisit how to rewrite loops as list comprehensions, how to choose between comprehensions and loops, and how to use conditional logic in your comprehensions.

Transforming Lists in Python

There are a few different ways to create and add items to a lists in Python. In this section, you’ll explore for loops and the map() function to perform these tasks. Then, you’ll move on to learn about how to use list comprehensions and when list comprehensions can benefit your Python program.

Use for Loops

The most common type of loop is the for loop. You can use a for loop to create a list of elements in three steps:

  1. Instantiate an empty list.
  2. Loop over an iterable or range of elements.
  3. Append each element to the end of the list.

If you want to create a list containing the first ten perfect squares, then you can complete these steps in three lines of code:

Python >>> squares = [] >>> for number in range(10): ... squares.append(number * number) ... >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Copied!

Here, you instantiate an empty list, squares. Then, you use a for loop to iterate over range(10). Finally, you multiply each number by itself and append the result to the end of the list.

Work With map Objects

For an alternative approach that’s based in functional programming, you can use map(). You pass in a function and an iterable, and map() will create an object. This object contains the result that you’d get from running each iterable element through the supplied function.

As an example, consider a situation in which you need to calculate the price after tax for a list of transactions:

Python >>> prices = [1.09, 23.56, 57.84, 4.56, 6.78] >>> TAX_RATE = .08 >>> def get_price_with_tax(price): ... return price * (1 + TAX_RATE) ... >>> final_prices = map(get_price_with_tax, prices) >>> final_prices <map object at 0x7f34da341f90> >>> list(final_prices) [1.1772000000000002, 25.4448, 62.467200000000005, 4.9248, 7.322400000000001] Copied!

Here, you have an iterable, prices, and a function, get_price_with_tax(). You pass both of these arguments to map() and store the resulting map object in final_prices. Finally, you convert final_prices into a list using list().

Leverage List Comprehensions

List comprehensions are a third way of making or transforming lists. With this elegant approach, you could rewrite the for loop from the first example in just a single line of code:

Python >>> squares = [number * number for number in range(10)] >>> squares [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Copied!

Rather than creating an empty list and adding each element to the end, you simply define the list and its contents at the same time by following this format:

Python Syntax new_list = [expression for member in iterable] Copied! Read the full article at https://realpython.com/list-comprehension-python/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Pages