skip to navigation
skip to content

Planet Python

Last update: August 20, 2024 04:43 AM UTC

August 19, 2024


TestDriven.io

Limiting Content Types in a Django Model

This article looks at how to limit the content types in a Django model.

August 19, 2024 10:28 PM UTC


Real Python

Python Classes: The Power of Object-Oriented Programming

Python supports the object-oriented programming paradigm through classes. They provide an elegant way to define reusable pieces of code that encapsulate data and behavior in a single entity. With classes, you can quickly and intuitively model real-world objects and solve complex problems.

If you’re new to classes, need to refresh your knowledge, or want to dive deeper into them, then this tutorial is for you!

In this tutorial, you’ll learn how to:

  • Define Python classes with the class keyword
  • Add state to your classes with class and instance attributes
  • Provide behavior to your classes with methods
  • Use inheritance to build hierarchies of classes
  • Provide interfaces with abstract classes

To get the most out of this tutorial, you should know about Python variables, data types, and functions. Some experience with object-oriented programming (OOP) is also a plus. Don’t worry if you’re not an OOP expert yet. In this tutorial, you’ll learn the key concepts that you need to get started and more. You’ll also write several practical examples to help reinforce your knowledge of Python classes.

Get Your Code: Click here to download your free sample code that shows you how to build powerful object blueprints with classes in Python.

Take the Quiz: Test your knowledge with our interactive “Python Classes - The Power of Object-Oriented Programming” quiz. You’ll receive a score upon completion to help you track your learning progress:


Interactive Quiz

Python Classes - The Power of Object-Oriented Programming

In this quiz, you'll test your understanding of Python classes. With this knowledge, you'll be able to define reusable pieces of code that encapsulate data and behavior in a single entity, model real-world objects, and solve complex problems.

Getting Started With Python Classes

Python is a multiparadigm programming language that supports object-oriented programming (OOP) through classes that you can define with the class keyword. You can think of a class as a piece of code that specifies the data and behavior that represent and model a particular type of object.

What is a class in Python? A common analogy is that a class is like the blueprint for a house. You can use the blueprint to create several houses and even a complete neighborhood. Each concrete house is an object or instance that’s derived from the blueprint.

Each instance can have its own properties, such as color, owner, and interior design. These properties carry what’s commonly known as the object’s state. Instances can also have different behaviors, such as locking the doors and windows, opening the garage door, turning the lights on and off, watering the garden, and more.

In OOP, you commonly use the term attributes to refer to the properties or data associated with a specific object of a given class. In Python, attributes are variables defined inside a class with the purpose of storing all the required data for the class to work.

Similarly, you’ll use the term methods to refer to the different behaviors that objects will show. Methods are functions that you define within a class. These functions typically operate on or with the attributes of the underlying instance or class. Attributes and methods are collectively referred to as members of a class or object.

You can write classes to model the real world. These classes will help you better organize your code and solve complex programming problems.

For example, you can use classes to create objects that emulate people, animals, vehicles, books, buildings, cars, or other objects. You can also model virtual objects, such as a web server, directory tree, chatbot, file manager, and more.

Finally, you can use classes to build class hierarchies. This way, you’ll promote code reuse and remove repetition throughout your codebase.

In this tutorial, you’ll learn a lot about classes and all the cool things that you can do with them. To kick things off, you’ll start by defining your first class in Python. Then you’ll dive into other topics related to instances, attributes, and methods.

Defining a Class in Python

To define a class, you need to use the class keyword followed by the class name and a colon, just like you’d do for other compound statements in Python. Then you must define the class body, which will start at the next indentation level:

Python Syntax
class ClassName:
    <body>
Copied!

In a class’s body, you can define attributes and methods as needed. As you already learned, attributes are variables that hold the class data, while methods are functions that provide behavior and typically act on the class data.

Note: In Python, the body of a given class works as a namespace where attributes and methods live. You can only access those attributes and methods through the class or its objects.

As an example of how to define attributes and methods, say that you need a Circle class to model different circles in a drawing application. Initially, your class will have a single attribute to hold the radius. It’ll also have a method to calculate the circle’s area:

Python circle.py
import math

class Circle:
    def __init__(self, radius):
        self.radius = radius

    def calculate_area(self):
        return math.pi * self.radius ** 2
Copied!

In this code snippet, you define Circle using the class keyword. Inside the class, you write two methods. The .__init__() method has a special meaning in Python classes. This method is known as the object initializer because it defines and sets the initial values for the object’s attributes. You’ll learn more about this method in the Instance Attributes section.

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


[ 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 ]

August 19, 2024 02:00 PM UTC


Mike Driscoll

How to Plot in the Terminal with Python and Textualize

Have you ever wanted to create a plot or graph in your terminal? Okay, maybe you haven’t, but now that you know you can, you want to! Python has the plotext package for plotting in your terminal. However, while that package is amazing all on its own, there is another package called textual-plotext that wraps the plotext package so you can use it in Textual!

In this tutorial, you will learn the basics of creating a plot in your terminal using the textual-plotext package!

Installation

Your first step in your plotting adventure is to install textual-plotext. You can install the package using pip. Open up your terminal and run the following command:

python -m pip install textual-plotext

Pip will install textual-plotext and any dependencies it needs. Once that’s done, you’re ready to start plotting!

Usage

To kick things off, you’ll create a simple Textual application with a scatter chart in it. This example comes from the textual-plotext GitHub repo. You can create a Python file and name it something like scatterplot.py and then add the following code:

from textual.app import App, ComposeResult

from textual_plotext import PlotextPlot

class ScatterApp(App[None]):

    def compose(self) -> ComposeResult:
        yield PlotextPlot()

    def on_mount(self) -> None:
        plt = self.query_one(PlotextPlot).plt
        y = plt.sin() # sinusoidal test signal
        plt.scatter(y)
        plt.title("Scatter Plot") # to apply a title

if __name__ == "__main__":
    ScatterApp().run()

When you run this code, you will see the following in your terminal:

Plotext Scatterplot in Textual

Plotext does more than scatterplots though. You can create any of the following:

Let’s look at a bar plot example:

from textual.app import App, ComposeResult

from textual_plotext import PlotextPlot

class BarChartApp(App[None]):

    def compose(self) -> ComposeResult:
        yield PlotextPlot()

    def on_mount(self) -> None:
        languages = ["Python", "C++", "PHP", "Ruby", "Julia", "COBOL"]
        percentages = [14, 36, 11, 8, 7, 4]
        plt = self.query_one(PlotextPlot).plt
        y = plt.bar(languages, percentages)
        plt.scatter(y)
        plt.title("Programming Languages") # to apply a title

if __name__ == "__main__":
    BarChartApp().run()

The main difference here is that you’ll be calling plt.bar() with some parameters, whereas,  in the previous example, you called plt.sin()with no parameters at all. Of course, you also need some data to plot for this second example. The provided data is all made up.

When you run this example, you will see something like the following:

Bar plot with plotext and textual

Isn’t that neat?

Wrapping Up

You can create many other plots with Plotext. Check out their documentation and give some of the other plots a whirl. Have fun and make cool things in your terminal today!

The post How to Plot in the Terminal with Python and Textualize appeared first on Mouse Vs Python.

August 19, 2024 12:44 PM UTC


PyCharm

The new and improved AI Assistant for the 2024.2 versions of JetBrains IDEs is now out, featuring smarter and faster AI code completion for Java, Kotlin, and Python; an enhanced UX when working with code in the editor; AI functionality for Git conflict resolution, in-terminal code generation, new customizable prompts, improved test generation, and more.

Don’t have AI Assistant yet? 

To experience the latest enhancements, simply open a project in your preferred JetBrains IDE version 2024.2, click the AI icon on the right toolbar to initiate the installation, and follow the instructions to enable it. 

You can also experience free local AI completion functionality with full line code completion (FLCC) in your IDE of choice, including CLion and Rider starting from 2024.2. Learn more about FLCC in this blog post. 

Faster and smarter cloud code completion

One of the main focuses of this release was to enhance the user experience of AI code completion in JetBrains IDEs. Here are some of the major advances we’ve made in this direction:

JetBrains code completion models for Python, Java, and Kotlin

We’ve significantly improved the quality and reduced the latency of our code completion for Java, Kotlin, and Python. These enhancements are powered by JetBrains’ internally trained large language models. Enhanced locations for cloud completion invocation extend the variety of usage scenarios, while improved suffix matching ensures that the predicted code snippet correctly completes the existing code.

Syntax highlighting for suggested code

Inline code completion suggestions now come with syntax highlighting, improving the readability of the suggested code.

Incremental acceptance of code suggestions

To simplify the process of reviewing suggestions, multiline code suggestions are now displayed only after accepting a single-line suggestion, allowing you to review and accept code gradually. Additionally, if you don’t want to accept an entire suggested line, you can accept it word by word using the same shortcut that you’d typically use to move the caret to the following word (Ctrl+→ for Windows and ⌥→ for macOS).

Seamless interaction of all available code completion types

We have made UX improvements to better integrate AI code completion features into IDE workflows. This includes a reworked UX for multiline completion and the ability to display suggestions alongside basic IDE completions.

Enhanced in-editor code generation

With the latest update, JetBrains IDEs now feature an improved AI code generation experience. Previously, generated code would open in a new tab. Now, it’s displayed directly in the current editor tab, allowing for an immediate review of the generated content. Check it out using the shortcut ⌘\ on macOS or Ctrl+\ on Windows and Linux.

AI chat becomes smarter

GPT-4o support

With the new release, AI Assistant now supports the latest GPT-4o model, bringing a boost to the AI Assistant’s chat-related functionalities, such as finding and explaining errors, explaining code, and refactoring.

Chat references and commands

We have introduced chat references and commands to enhance your AI Assistant’s chat experience, giving you more control over your context. Now, you can reference any symbols, allowing you to quickly indicate the context of your query and get more precise responses. Additionally, you can easily mention specific files or uncommitted local changes. Supported commands include /explain and /refactor, allowing you to quickly get explanations or refactor selected code without typing out questions in the chat.

New feature: merge VCS conflicts with AI

When multiple contributors are making changes to the same part of the codebase, and you try to pull your changes, conflicts may arise. To avoid any issues down the line, JetBrains IDEs now provide a tool for reviewing and resolving any such conflicts. Starting from version 2024.2, the Git conflict resolution modal dialog features AI capabilities to assist with merging conflicts. After AI has done its job, you can review the merged result and either accept everything or revert the changes individually. 

New feature: AI-powered command generation in the new Terminal

Generate commands with AI directly in your IDE via the new Terminal tool window. This integration ensures you can efficiently complete command-line tasks without distraction, improving your overall workflow.

Enhanced unit test generation with AI Assistant

Starting from version 2024.2, the Generate Unit Tests action can be invoked not only on methods but also on classes. If a class has multiple methods, the AI will automatically choose the most suitable one for testing. The latest update also includes more customization options for unit test generation. 

Customizable unit test guidelines

Users can set their own unit test guidelines by customizing the test generation prompt in the AI Assistant’s Prompt Library. This allows you to add specific testing rules for Java, Kotlin, JavaScript, Go, Python, PHP, and Ruby.

Adding test cases to existing tests

AI Assistant now supports adding new test cases to existing test files for Java and Kotlin, allowing you to generate new tests using AI.

Сustom prompts for documentation generation 

The latest update to JetBrains IDEs introduces customizable documentation generation prompts. This feature allows the model to generate documentation for a selected code element and inserts it directly into the code. Users can now define the desired content of the generated documentation for different languages and specify various formatting options, such as Javadoc for Java, ensuring the documentation adheres to preferred styles and standards.

Natural Language setting

You can now specify the language in which you want to interact with the AI chat via Settings. After enabling the Natural Language setting, the context of the current chat will be updated, and any new answers generated by the AI will be provided in the user’s chosen language.

Using AI for working with databases

The new release brings AI to a variety of database-specific features within JetBrains IDEs. You can try these out in DataGrip or in a JetBrains IDE of your choice using the bundled Database Tools and SQL plugin.

Get AI assistance when modifying tables

AI Assistant can now help you change the database-specific parameters of a table. Ask AI Assistant to modify a table according to your requirements right in the Modify dialog. Once AI Assistant generates the requested SQL code, you’ll be able to review it in the preview pane of the dialog and then apply the changes.

Explain and fix SQL problems


DataGrip’s code inspections detect various issues with your SQL queries before execution, which are then categorized according to predefined severity levels.

The latest update integrates AI to enhance the comprehension and resolution of SQL problems. For issues with a severity level higher than Weak warning, the AI Assistant offers explanations and fixes. For better context and more accurate suggestions, you can also attach your database schema.

AI Enterprise: unlocking organizational productivity

Are you looking to maximize productivity at an organizational scale? AI Enterprise runs on premises as part of JetBrains IDE Services, ensuring complete control over data and AI operations within your organization’s infrastructure. It also provides AI usage statistics and reports, offering insights into how AI tools are utilized across your development teams. Learn more about AI Enterprise.

Enhance your writing with Grazie, now included in the AI Pro subscription plan

We’re excited to share that Grazie, our AI writing companion for people in tech, is now included in the AI Pro subscription plan. Use Grazie to transform your thoughts into clear, well-articulated writing, with features like instant proofreading, inline text completion, summarization, translation, rephrasing, and more!

Grazie is now available as a plugin for your JetBrains IDEs and as an extension for browsers. While there is a free version, AI Pro subscribers enjoy full volume access to the entire suite of Grazie’s AI features, which is 500 times greater than the basic volume and replenishes weekly.

Explore AI Assistant and share your feedback

You can learn more about AI Assistant’s key features here. However, the best way to explore its capabilities is by trying it out yourself.

As always, we look forward to hearing your feedback. You can also tell us about your experience via the Share your feedback link in the AI Assistant tool window or by submitting feature requests or bug reports in YouTrack.

Happy developing!

August 19, 2024 10:41 AM UTC

Introducing the PyCharm Databricks Integration

We’re introducing the Databricks integration with PyCharm Professional to make it easier for you to process, store, and analyze your data! 

The integration allows you to build your data and AI apps on the Databricks Data Intelligence Platform directly within PyCharm Professional, enhancing the data analytics platform with the powerful Python IDE by JetBrains. It enables you to write code quickly and easily and run it in the cloud without extra configurations, and it offers additional benefits for working with data. 

Read this blog post to learn more about the integration, who it will be useful for, and what benefits it offers.

Watch the plugin in action

What is Databricks?

The Databricks Data Intelligence Platform allows your entire organization to use data and AI. It’s built on a lakehouse to provide an open, unified foundation for all data and governance, and is powered by a Data Intelligence Engine that understands the uniqueness of your data.

What is PyCharm Professional?

PyCharm Professional is a leading IDE for Python and other programming languages. It allows you to write high-quality and efficient code using superior code completion, refactoring capabilities, code inspections, seamless code and project navigation, a debugger, and a wide range of integrations, including Jupyter notebooks, testing frameworks, Git, CI/CD solutions, and more – all available in one place right out of the box.

Who will the integration be useful for? 

Organizations and data professionals using data lakehouses, data lakes, and data warehouses via Databricks will benefit from this integration.

What benefits does the integration bring?

The integration combines the most powerful capabilities of each platform, allowing you to easily build all of your data and AI applications at scale within PyCharm: 

You can write the code for your pipelines and jobs in PyCharm, then deploy, test, and run it in real time on your Databricks cluster without any additional configurations. 

Let’s dive into more details about what the PyCharm Databricks integration provides.

Connect to your cluster via PyCharm

You can connect directly to the Databricks cluster via PyCharm and monitor the process within the IDE. This allows you to check if the cluster is running, see the results of the current session’s runs, and view process outcomes along with additional details.

Connect to your cluster via PyCharm

Run Python scripts on a remote cluster

In addition, you can run Python scripts on a remote cluster, which is particularly useful for working with big data, and view the results in the IDE.

Run Python scripts on a remote cluster

Run Jupyter notebooks or Python scripts as workflows

Additionally, you can run your notebook or Python scripts as a Databricks workflow and see the output in the console. 

Run Jupyter notebooks or Python scripts as workflows

You can see the results of the runs on the Databricks platform, including the runs initiated from PyCharm.

See the results of the runs on the Databricks platform from PyCharm

Synchronize project files to the Databricks workspace

The synchronization of project files with the Databricks workspace allows you to access and work with the same files in both PyCharm and Databricks workspaces. You can also schedule your notebooks and scripts and utilize other platform features for projects completed in PyCharm. 

Synchronize project files to the Databricks workspace

How to get started

Make sure you have the following ready to go:

You can install the Databricks plugin either from JetBrains Marketplace or directly from within the PyCharm IDE.

Head over to the documentation to get step-by-step instructions on how to get started and use the plugin.

What do you think about this integration? Share your thoughts in the comments below.

August 19, 2024 08:47 AM UTC


Talk Python to Me

#474: Python Performance for Data Science

Python performance has come a long way in recent times. And it's often the data scientists, with their computational algorithms and large quantities of data, who care the most about this form of performance. It's great to have Stan Seibert back on the show to talk about Python's performance for data scientists. We cover a wide range of tools and techniques that will be valuable for many Python developers and data scientists.<br/> <br/> <strong>Episode sponsors</strong><br/> <br/> <a href='https://talkpython.fm/posit'>Posit</a><br> <a href='https://talkpython.fm/training'>Talk Python Courses</a><br/> <br/> <strong>Links from the show</strong><br/> <br/> <div><b>Stan on Twitter</b>: <a href="https://twitter.com/seibert?featured_on=talkpython" target="_blank" >@seibert</a><br/> <b>Anaconda</b>: <a href="https://www.anaconda.com?featured_on=talkpython" target="_blank" >anaconda.com</a><br/> <b>High Performance Python with Numba training</b>: <a href="https://bit.ly/3y03dK6?featured_on=talkpython" target="_blank" >learning.anaconda.cloud</a><br/> <b>PEP 0703</b>: <a href="https://peps.python.org/pep-0703/?featured_on=talkpython" target="_blank" >peps.python.org</a><br/> <b>Python 3.13 gets a JIT</b>: <a href="https://tonybaloney.github.io/posts/python-gets-a-jit.html?featured_on=talkpython" target="_blank" >tonybaloney.github.io</a><br/> <b>Numba</b>: <a href="https://numba.pydata.org?featured_on=talkpython" target="_blank" >numba.pydata.org</a><br/> <b>LanceDB</b>: <a href="https://lancedb.com?featured_on=talkpython" target="_blank" >lancedb.com</a><br/> <b>Profiling tips</b>: <a href="https://docs.python.org/3/library/profile.html?featured_on=talkpython" target="_blank" >docs.python.org</a><br/> <b>Memray</b>: <a href="https://github.com/bloomberg/memray?featured_on=talkpython" target="_blank" >github.com</a><br/> <b>Fil: a Python memory profiler for data scientists and scientists</b>: <a href="https://pythonspeed.com/articles/memory-profiler-data-scientists/?featured_on=talkpython" target="_blank" >pythonspeed.com</a><br/> <b>Rust</b>: <a href="https://www.rust-lang.org?featured_on=talkpython" target="_blank" >rust-lang.org</a><br/> <b>Granian Server</b>: <a href="https://github.com/emmett-framework/granian/blob/master/benchmarks/vs.md?featured_on=talkpython" target="_blank" >github.com</a><br/> <b>PIXIE at SciPy 2024</b>: <a href="https://github.com/numba/pixie/blob/main/scipy2024/README.rst?featured_on=talkpython" target="_blank" >github.com</a><br/> <b>Free threading Progress</b>: <a href="https://py-free-threading.github.io/?featured_on=talkpython" target="_blank" >py-free-threading.github.io</a><br/> <b>Free Threading Compatibility</b>: <a href="https://py-free-threading.github.io/tracking/?featured_on=talkpython" target="_blank" >py-free-threading.github.io</a><br/> <b>caniuse.com</b>: <a href="https://caniuse.com/?search=webworkers&featured_on=talkpython" target="_blank" >caniuse.com</a><br/> <b>SPy, presented at PyCon 2024</b>: <a href="https://us.pycon.org/2024/schedule/presentation/70/?featured_on=talkpython" target="_blank" >us.pycon.org</a><br/> <b>Watch this episode on YouTube</b>: <a href="https://www.youtube.com/watch?v=WacFkcNIKxc" target="_blank" >youtube.com</a><br/> <b>Episode transcripts</b>: <a href="https://talkpython.fm/episodes/transcript/474/python-performance-for-data-science" target="_blank" >talkpython.fm</a><br/> <br/> <b>--- Stay in touch with us ---</b><br/> <b>Subscribe to us on YouTube</b>: <a href="https://talkpython.fm/youtube" target="_blank" >youtube.com</a><br/> <b>Follow Talk Python on Mastodon</b>: <a href="https://fosstodon.org/web/@talkpython" target="_blank" ><i class="fa-brands fa-mastodon"></i>talkpython</a><br/> <b>Follow Michael on Mastodon</b>: <a href="https://fosstodon.org/web/@mkennedy" target="_blank" ><i class="fa-brands fa-mastodon"></i>mkennedy</a><br/></div>

August 19, 2024 08:00 AM UTC


EuroPython

EuroPython 2024: Post Conference Feedback

Its been a month now since EuroPython 2024 took place and as the dust settles, we’ve gathered feedback from 157 attendees to understand what made this year’s event special, what challenges were faced, and how the experience can shape future EuroPythons. Whether you were there in person or followed along online, join us as we dive into the analysing the feedback!

The data we have represents around 13% of the onsite attendees and around 11% of total attendees. It is difficult to tell whether this is a representative sample as we did not collect demographic data.

Satisfaction with the conference

Attendees were overall very satisfied with the conference, with a mean overall satisfaction rating of 4.3. Moreover, attendees were satisfied with most specific aspects of the conference, including the venue (mean = 4.6), food (mean = 4.0), and the social event (mean = 4.0). Attendees particularly liked that the conference was hosted in Prague, with the location getting a mean rating of 4.7.

Overall, the satisfaction ratings that had the strongest relationship (Spearman correlation) with overall satisfaction with the conference were the food (rs = 0.20) and the social event (rs = 0.17); however, these are still very modest correlations, indicating that other factors we did not measure were stronger drivers of satisfaction with the conference

altMean and standard deviation of ratings per conference aspect

Things that people liked about the conference

Two of the feedback survey questions were free text which asked attendees to comment on what they did and did not like overall about the conference. Ninety-seven respondents gave positive feedback, and 92 gave negative feedback.

In order to make these easier to analyse, used a large language model to extract the topics that each attendee was talking about in their responses. This was by no means perfect, so take it as a guide rather than something totally objective (e.g., “organisation” was pretty broadly interpreted by the model).

The top topics (where at least 5 people had mentioned them in their feedback) in the “liked” feedback are listed below.

Liked topics

Number of respondents who mentioned topic

Community

37

Food

20

Organisation

19

Talks

16

Networking

14

Atmosphere

14

Venue

10

Communication

5

Location

5

We have also plotted these topics by their mentions for better understanding

alt

With a general overview of the feedback on EuroPython 2024 in mind, let&aposs delve into specific aspects of the conference such as the food, talks, workshops, and more

Food & Catering

As noted above in the first graph, people were overall satisfied with the food. When breaking this down by dietary requirements, satisfaction varied a bit more.

Note: we have very small samples for some of these special dietary groups,

Dietary requirement

Total respondents

Mean satisfaction rating

None

115

4.13

Vegetarian

23

3.82

Vegan

11

4.00

Gluten-free

2

3.50

Lactose-intolerant

4

4.00

Low-carb

2

3.50

Halal

4

3.00

Kosher

1

5.00

Other

2

2.50

altAverage Satisfaction with food grouped by Dietary requirements

PyLadies workshops

Only 28 respondents indicated that they had attended at least one PyLadies workshop, so we should interpret the below findings with caution. However, mean satisfaction with the PyLadies events was high (4.43). Below is the breakdown of mean satisfaction per PyLadies event (some people attended multiple events, hence the total exceeds 28).

PyLadies event

Total respondents

Mean satisfaction rating

Wednesday evening social event

16

4.43

Self-Defense workshop

7

4.29

PyLadies lunch

16

4.38

#IAmRemarkable workshop

1

5.00

alt

Community tutorials

Only 8 respondents indicated that they had attended at least one of the community tutorials so unfortunately this means we cannot break down the data by tutorial. However, the overall mean satisfaction rating was high (4.0).

Talks

Attendees were asked to give feedback on which talks they particularly liked, and which ones they didn&apost like. 104 attendees gave feedback on which talks they liked, and 59 gave feedback on talks they did not like.

We normalised the feedback by matching it up to the closest title, and then checking this manually.  The findings are broken down below by talk level, type and track, as well as the most liked speakers.

Level

Attendees seemed to enjoy talks across all levels equally, with around 4 times more people liking versus disliking talks at each level.

Talk level

Number of talks at conference

Number of liked talks

Number of disliked talks

Average number of likes per talk

Average number of dislikes per talk

Ratio of likes to dislikes

beginner

65

138

35

2.1

0.54

3.9

intermediate

93

178

46

1.9

0.49

3.9

advanced

14

23

6

1.6

0.43

3.8

Type

By far the most popular type of talk were long talk sessions. These talks received a lot of feedback, with 15 times more attendees saying they liked these talks versus disliking them. The keynotes were also well received, with 4 times more people mentioning liking them versus disliking them.

Posters were only mentioned once in the feedback. While it is hard to say from this feedback as it does not measure attendance, it is possible these sessions were not well attended.

Talk type

Number of talks at conference

Number of liked talks

Number of disliked talks

Average number of likes per talk

Average number of dislikes per talk

Ratio of likes to dislikes

Talk (long session)

25.0

61.0

4.0

2.4

0.16

15.2

Keynote

6.0

84.0

20.0

14

3.33

4.2

Talk

92.0

174.0

51.0

1.9

0.55

3.4

Tutorial

16.0

9.0

5.0

0.6

0.31

1.8

Sponsored

8.0

8.0

6.0

1

0.75

1.3

Conference Workshop



1.0


0.25


Panel

2.0

2.0


1



Poster

9.0

1.0


0.1



Track

While it is hard to draw robust conclusions for this category as there are very small samples in most of the tracks, some particularly popular tracks (with a high ratio of likes to dislikes and high number of overall likes) are:

track

Number of talks at conference

Number of liked talks

Number of disliked talks

Average number of likes per talk

Average number of dislikes per talk

Ratio of likes to dislikes

Arts, Crafts Culture & Demos

3

30

1.0

10.0

0.33

30.0

Testing and QA

5

17

1.0

3.4

0.2

17.0

Career, Life, Health

4

28

2.0

7.0

0.5

14.0

PyData: Deep Learning, NLP, CV

8

7

1.0

0.88

0.13

7.0

DevOps and Infrastructure (Cloud & Hardware)

5

13

2.0

2.6

0.4

6.5

Python Libraries & Tooling

23

49

10.0

2.13

0.43

4.9

Web technologies

9

4

1.0

0.44

0.11

4.0

Python Internals & Ecosystem

24

62

18.0

2.58

0.75

3.4

Education, Community & Diversity

7

19

7.0

2.71

1.0

2.7

PyData: LLMs

10

15

6.0

1.5

0.6

2.5

PyData: Data Engineering

10

9

4.0

0.9

0.4

2.3

Software Engineering & Architecture

14

31

14.0

2.21

1.0

2.2

Security

6

4

3.0

0.67

0.5

1.3

PyData: Machine Learning, Stats

7

3

3.0

0.43

0.43

1.0

~ None of these topics

3

1

1.0

0.33

0.33

1.0

PyData: Research & Applications

6

1

2.0

0.17

0.33

0.5

Ethics, Philosophy & Politics

1

1


1.0



PyData: Software Packages & Jupyter

5

7


1.4



Special thank you to our amazing data wizard Jodie Burchell for putting together together this report!

If you have any questions, you are welcome to reach out to the team at helpdesk@europython.eu

August 19, 2024 06:23 AM UTC

August 16, 2024


Glyph Lefkowitz

On The Defense Of Heroes

If a high-status member of a community that you participate in is accused of misbehavior, you may want to defend them. You may even write a long essay in their defense.

In that essay, it may seem only natural to begin with a lengthy enumeration of the accused’s positive personal qualities. To extol the quality of their career and their contributions to your community. To talk about how nice they are. To be a character witness in the court of public opinion.

If you do this, you are not defending them. You are proving the point. This is exactly how missing stairs come to exist. People don’t get away with bad behavior if they don’t have high status and a good reputation already.

Sometimes, someone with antisocial inclinations seeks out status, in order to facilitate their bad behavior. Sometimes, a good, but, flawed person does a lot of really good work and thereby accidentally ends up with more status than they were expecting to have, and they don’t know how to handle it. In either case, bad behavior may ensue.

If you truly believe that your fave is being accused or punished unjustly, focus on the facts. What, specifically, has been alleged? How are these allegations substantiated? What verifiable evidence exists to the contrary? If you feel that someone is falsely accusing them to ruin their reputation, is there evidence to support your claim that the accusation is false? Ask yourself the question: what information do you have, that is leading to your correct analysis of the situation, that the people making the accusations do not have, which might be leading them into error?

But, also, maybe just… don’t?

The urge to defend someone like this is much more likely to come from a sense of personal grievance than justice. Consider: does it feel like you are being attacked, when your fave has been attacked? Is there a tightness in your chest, heat rising on your cheeks? Do you feel suddenly defensive?

Do you think that defensiveness is likely to lead to you making good, rational decisions about what steps to take next?

Let your heroes face accountability. If they are really worth your admiration, they might accept responsibility and make amends. Or they might fight the accusations with their own real evidence — evidence that you, someone peripheral to their situation, are unlikely to have — and prove the accusations wrong.

They might not want your defense. Even if they feel like they do want it in the moment — they are human too, after all, and facing accountability does not feel good to us humans — is the intensified feeling that they can’t let down their supporters who believe in them likely to make them feel less defensive and panicked?

In either case, your character defense is unlikely to serve them. At best it helps them stay on an ego trip, at worst it muddies the waters and might confuse the collection of facts that would, if considered dispassionately, properly exonerate them.

Do you think that I am pretending to speak in generalities but really talking about one specific recent event?

Wrong!

Just in this last week, I have read 2 different blog posts about 2 completely different people in completely unrelated communities and both of their authors need to read this. But each of those were already of a type, one that I’ve read dozens of instances of in the past.

It is a very human impulse to perceive a threat to someone we think well of, and to try to defend against that threat. But the consequences of someone’s own actions are not a threat you can defend them from.

August 16, 2024 07:53 PM UTC


Real Python

The Real Python Podcast – Episode #217: Packaging Data Analyses & Using pandas GroupBy

What are the best practices for organizing data analysis projects in Python? What are the advantages of a more package-centric approach to data science? Christopher Trudeau is back on the show this week, bringing another batch of PyCoder's Weekly articles and projects.


[ 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 ]

August 16, 2024 12:00 PM UTC

Quiz: Web Scraping With Scrapy and MongoDB

In this quiz, you’ll test your understanding of Web Scraping with Scrapy and MongoDB.

By working through this quiz, you’ll revisit how to set up a Scrapy project, build a functional web scraper, extract data from websites using selectors, store scraped data in a MongoDB database, and test and debug your Scrapy web scraper.


[ 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 ]

August 16, 2024 12:00 PM UTC


Anarcat

Why I should be running Debian unstable right now

So a common theme on the Internet about Debian is so old. And right, I am getting close to the stage that I feel a little laggy: I am using a bunch of backports for packages I need, and I'm missing a bunch of other packages that just landed in unstable and didn't make it to backports for various reasons.

I disagree that "old" is a bad thing: we definitely run Debian stable on a fleet of about 100 servers and can barely keep up, I would make it older. And "old" is a good thing: (port) wine and (any) beer needs time to age properly, and so do humans, although some humans never seem to grow old enough to find wisdom.

But at this point, on my laptop, I am feeling like I'm missing out. This page, therefore, is an evolving document that is a twist on the classic NewIn game. Last time I played seems to be #newinwheezy (2013!), so really, I'm due for an update. (To be fair to myself, I do keep tabs on upgrades quite well at home and work, which do have their share of "new in", just after the fact.)

New packages to explore

Those tools are shiny new things available in unstable or perhaps Trixie (testing) already that I am not using yet, but I find interesting enough to list here.

New packages I won't use

Those are packages that I have tested because I found them interesting, but ended up not using, but I think people could find interesting anyways.

Backports already in use

Those are packages I already use regularly, which have backports or that can just be installed from unstable:

Out of date packages

Those are packages that are in Debian stable (Bookworm) already, but that are somewhat lacking and could benefit from an upgrade.

Last words

If you know of cool things I'm missing out of, then by all means let me know!

That said, overall, this is a pretty short list! I have most of what I need in stable right now, and if I wasn't a Debian developer, I don't think I'd be doing the jump now. But considering how easier it is to develop Debian (and how important it is to test the next release!), I'll probably upgrade soon.

Previously, I was running Debian testing (which why the slug on that article is why-trixie), but now I'm actually considering just running unstable on my laptop directly anyways. It's been a long time since we had any significant instability there, and I can typically deal with whatever happens, except maybe when I'm traveling, and then it's easy to prepare for that (just pin testing).

August 16, 2024 03:41 AM UTC


Matt Layman

More Go Standard Library - Building SaaS #198

In this episode, we continued the break from JourneyInbox to look through more of the Go standard library. In this session, we explored JSON serialization, Go template support, and embedding of static files for easy access.

August 16, 2024 12:00 AM UTC

August 15, 2024


Matt Layman

PDF Text Extraction With Python

Is your data locked up in portable document format (PDFs)? In this talk we’re going to explore methods to extract text and other data from PDFs using readily-available, open-source Python tools (such as pypdf), as well as techniques such as OCR (optical character recognition) and table extraction. We will also discuss the philosophy of text extraction as a whole.

August 15, 2024 12:00 AM UTC

August 14, 2024


Real Python

The Walrus Operator: Python's Assignment Expressions

Each new version of Python adds new features to the language. Back when Python 3.8 was released, the biggest change was the addition of assignment expressions. Specifically, the := operator gave you a new syntax for assigning variables in the middle of expressions. This operator is colloquially known as the walrus operator.

This tutorial is an in-depth introduction to the walrus operator. You’ll learn some of the motivations for the syntax update and explore examples where assignment expressions can be useful.

In this tutorial, you’ll learn how to:

  • Identify the walrus operator and understand its meaning
  • Understand use cases for the walrus operator
  • Avoid repetitive code by using the walrus operator
  • Convert between code using the walrus operator and code using other assignment methods
  • Use appropriate style in your assignment expressions

Note that all walrus operator examples in this tutorial require Python 3.8 or later to work.

Get Your Code: Click here to download the free sample code that shows you how to use Python’s walrus operator.

Take the Quiz: Test your knowledge with our interactive “The Walrus Operator: Python's Assignment Expressions” quiz. You’ll receive a score upon completion to help you track your learning progress:


Interactive Quiz

The Walrus Operator: Python's Assignment Expressions

In this quiz, you'll test your understanding of the Python Walrus Operator. This operator was introduced in Python 3.8, and understanding it can help you write more concise and efficient code.

Walrus Operator Fundamentals

First, look at some different terms that programmers use to refer to this new syntax. You’ve already seen a few in this tutorial.

The := operator is officially known as the assignment expression operator. During early discussions, it was dubbed the walrus operator because the := syntax resembles the eyes and tusks of a walrus lying on its side. You may also see the := operator referred to as the colon equals operator. Yet another term used for assignment expressions is named expressions.

Hello, Walrus!

To get a first impression of what assignment expressions are all about, start your REPL and play around with the following code:

Python
 1>>> walrus = False
 2>>> walrus
 3False
 4
 5>>> (walrus := True)
 6True
 7>>> walrus
 8True
Copied!

Line 1 shows a traditional assignment statement where the value False is assigned to walrus. Next, on line 5, you use an assignment expression to assign the value True to walrus. After both lines 1 and 5, you can refer to the assigned values by using the variable name walrus.

You might be wondering why you’re using parentheses on line 5, and you’ll learn why the parentheses are needed later on in this tutorial.

Note: A statement in Python is a unit of code. An expression is a special statement that can be evaluated to some value.

For example, 1 + 2 is an expression that evaluates to the value 3, while number = 1 + 2 is an assignment statement that doesn’t evaluate to a value. Although running the statement number = 1 + 2 doesn’t evaluate to 3, it does assign the value 3 to number.

In Python, you often see simple statements like return statements and import statements, as well as compound statements like if statements and function definitions. These are all statements, not expressions.

There’s a subtle—but important—difference between the two types of assignments with the walrus variable. An assignment expression returns the value, while a traditional assignment doesn’t. You can see this in action when the REPL doesn’t print any value after walrus = False on line 1 but prints out True after the assignment expression on line 5.

You can see another important aspect about walrus operators in this example. Though it might look new, the := operator does not do anything that isn’t possible without it. It only makes certain constructs more convenient and can sometimes communicate the intent of your code more clearly.

Now you have a basic idea of what the := operator is and what it can do. It’s an operator used in assignment expressions, which can return the value being assigned, unlike traditional assignment statements. To get deeper and really learn about the walrus operator, continue reading to see where you should and shouldn’t use it.

Implementation

Like most new features in Python, assignment expressions were introduced through a Python Enhancement Proposal (PEP). PEP 572 describes the motivation for introducing the walrus operator, the details of the syntax, and examples where the := operator can be used to improve your code.

This PEP was originally written by Chris Angelico in February 2018. Following some heated discussion, PEP 572 was accepted by Guido van Rossum in July 2018.

Since then, Guido announced that he was stepping down from his role as benevolent dictator for life (BDFL). Since early 2019, the Python language has been governed by an elected steering council instead.

The walrus operator was implemented by Emily Morehouse, and made available in the first alpha release of Python 3.8.

Motivation

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


[ 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 ]

August 14, 2024 02:00 PM UTC

Quiz: The Walrus Operator: Python's Assignment Expressions

In this quiz, you’ll test your understanding of the Python Walrus Operator. This operator, used for assignment expressions, was introduced in Python 3.8 and can be used to assign values to variables as part of an expression.


[ 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 ]

August 14, 2024 12:00 PM UTC


Python Anywhere

Postal code validation for card payments

TL;DR

We recently started validating that the postal codes used for paid PythonAnywhere accounts match the ones that people’s banks have on file for the card used. This has led to some confusion, in particular because banks handle postal code validation in a complicated way – charges that fail because of this kind of error can show up in your bank app as a payment that then disappears later, or even as a charge followed by a refund. This blog post is to summarise why that is, so hopefully it will make things a bit less confusing!

The long version…

Card fraud is, sadly, a fact of life on the Internet. If you have a website that accepts payments, eventually someone will try to use a stolen card on it. If your site is online for some time, hackers might even start using you to test lists of stolen cards – that is, they don’t want to use your product in particular, they’re just trying each of the cards to find the ones that are valid, so that they can use them elsewhere.

We recently saw an uptick in the number of these “card probers” (as we call them internally) on PythonAnywhere. We have processes in place to identify them, so that we can refund all payments they get through, and report them as fraudulent to Stripe – our card processor – so that the cards in question are harder for them to use on other sites. But this takes time – time which we would much rather spend on building new features for PythonAnywhere.

Looking into the recent charges, we discovered that many of them were using the wrong postal code when testing the cards. The probers had the numbers, the expiry dates, the CVVs, but not the billing addresses. So we re-introduced something that had been disabled on our Stripe account for some time: postal code validation for payments. You may be wondering why it wasn’t enabled already, or why it might even be something that anyone would disable; this blog post is an introduction to why postal codes and card payments can be more complicated than you might think.

August 14, 2024 11:00 AM UTC


Paolo Melchiorre

Python Software Foundation fellow member

The Python Software Foundation made me a PSF fellow member, along with Adam Johnson.

August 14, 2024 09:55 AM UTC

August 13, 2024


PyCoder’s Weekly

Issue #642 (Aug. 13, 2024)

#642 – AUGUST 13, 2024
View in Browser »

The PyCoder’s Weekly Logo


Testing Coverage and Using nox

This is part 9 in an in-depth series on testing. This part talks about using coverage tools to check how much of your code gets executed during tests, and how to use the nox tool to test against a matrix of Python and dependency versions.
BITE CODE!

Asynchronous Iterators and Iterables in Python

In this tutorial, you’ll learn how to create and use asynchronous iterators and iterables in Python. You’ll explore their syntax and structure and discover how they can be leveraged to handle asynchronous operations more efficiently.
REAL PYTHON

500 Devs, Deploying 200x a Day, While Maintaining 4 Million Lines of Code 😮‍💨

alt

Sounds tricky right? Well that’s exactly what Kraken Technologies is doing. Learn how they manage 100s of deployments a day and how they handle errors when they crop up. Sneak peak: they use Sentry to reduce noise, prioritize issues, and maintain code quality–without relying on a dedicated QA team →
SENTRY sponsor

Log Context Propagation in Python ASGI Apps

This explains how to automatically attach contextual information to all the log messages coming out of a Python ASGI application.
REDOWAN DELOWAR • Shared by Redowan Delowar

PEP 750: Tag Strings for Domain-Specific Languages (Added)

PEP

Python 3.12.5 Released

CPYTHON DEV BLOG

Django Security Releases: 5.0.8 and 4.2.15

DJANGO SOFTWARE FOUNDATION

Django 5.1 Released

DJANGO SOFTWARE FOUNDATION

Quiz: Python Basics: Lists and Tuples

REAL PYTHON

Quiz: How to Write Beautiful Python Code With PEP 8

REAL PYTHON

Articles & Tutorials

Fixing CTRL+left and CTRL+right in the REPL on macOS

The upcoming release of Python 3.13 has some great new features in the REPL making it easier to move around and edit your code. One feature is the ability to move word by word using CTRL+left and right arrow keys. Unfortunately, macOS traps these keys. This quick TIL post shows you how to fix that.
RODRIGO GIRÃO SERRÃO

Strings and Character Data in Python

In this tutorial, you’ll learn how to use Python’s rich set of operators and functions for working with strings. You’ll cover the basics of creating strings using literals and the str() function, applying string methods, using operators and built-in functions with strings, and more!
REAL PYTHON

Learning Through Building the Black Python Devs Community

What hurdles must be cleared when starting an international organization? How do you empower others in a community by sharing responsibilities? This week on the show, we speak with Jay Miller about Black Python Devs.
REAL PYTHON podcast

Taking Notes on a New Codebase

Nat is a consultant which means they spend a lot of time reading other people’s code. When trying to understand large systems taking notes along the way can help. This post talks about the techniques Nat uses.
NAT BENNETT

Create Amazing Progress Bars in Python With alive-progress

Have you ever needed a progress bar in your Python command-line application? One great way of creating a progress bar is to use the alive-progress package. This article shows you how.
MIKE DRISCOLL

PyCon US 2024 Recap and Recording Release

PyCon US 2024 had a record breaking attendance with over 2,700 in-person tickets sold. This article is a recap from the conference runners and links to all the available recordings.
PYCON

Knuckledragger, a Semi-Automated Python Proof Assistant

This post describes Knuckledragger, a Z3 based semi-automated proof assistant. The post covers the basic design, applications, and a variety of theory types it can work with.
PHILIP ZUCKER

Python Extensions Should Be Lazy

Evan has been using the ast.parse function a lot and has found it to be slow even though it is built as a C extension. This article digs into what is going on.
EVAN DOYLE

SonarQube: Open Source Security Automation

SonarQube is a freely available static code analysis tool. This article shows you what it can do and how to get it going on your system.
PRINCE ONYEANUNA

The Trouble With __all__

This post talks about the __all__ attribute and how it declares the public interface to a module, but does not enforce access.
CAELEAN BARNES

Parsing nginx Server Logs With Regular Expressions

This practical article on regular expressions shows you how to build regexes to parse the logs from the nginx web server.
JUHA-MATTI SANTALA

Python’s Operator Precedence

Stephen uses a story-telling style to explain how operator precedence works in Python.
STEPHEN GRUPPETTA • Shared by Stephen Gruppetta

Projects & Code

RustPython: A Python Interpreter Written in Rust

GITHUB.COM/RUSTPYTHON

fasthtml: The Fastest Way to Create an HTML App

GITHUB.COM/ANSWERDOTAI

wat: Deep Inspection of Python Objects

GITHUB.COM/IGREK51

zulip-terminal: Official Zulip Chat Terminal Client

GITHUB.COM/ZULIP

emptylog: Expand the Logger Protocol and Test Logs

GITHUB.COM/POMPONCHIK • Shared by Evgeniy Blinov (pomponchik)

Events

Weekly Real Python Office Hours Q&A (Virtual)

August 14, 2024
REALPYTHON.COM

PyData Bristol Meetup

August 15, 2024
MEETUP.COM

PyLadies Dublin

August 15, 2024
PYLADIES.COM

SheDevelopers: Python Mastery Workshop 1st Edition

August 16 to August 17, 2024
SHEDEVSPYTHONWORKSHOP.CO.ZW

PyCon Somalia 2024

August 21 to August 23, 2024
PYCON.ORG.SO

Kiwi PyCon XIII

August 23 to August 26, 2024
KIWIPYCON.NZ


Happy Pythoning!
This was PyCoder’s Weekly Issue #642.
View in Browser »

alt

[ Subscribe to 🐍 PyCoder’s Weekly 💌 – Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]

August 13, 2024 07:30 PM UTC


Python Software Foundation

Announcing Python Software Foundation Fellow Members for Q1 2024! 🎉

The PSF is pleased to announce its first batch of PSF Fellows for 2024! Let us welcome the new PSF Fellows for Q1! The following people continue to do amazing things for the Python community:

Adam Johnson

Website, Mastodon, Github

Paolo Melchiorre 

Website, Mastodon, GitHub, Stack Overflow, YouTube, LinkedIn, X

Thank you for your continued contributions. We have added you to our Fellow roster.

The above members help support the Python ecosystem by being phenomenal leaders, sustaining the growth of the Python scientific community, maintaining virtual Python communities, maintaining Python libraries, creating educational material, organizing Python events and conferences, starting Python communities in local regions, and overall being great mentors in our community. Each of them continues to help make Python more accessible around the world. To learn more about the new Fellow members, check out their links above.

Let's continue recognizing Pythonistas all over the world for their impact on our community. The criteria for Fellow members is available online: https://www.python.org/psf/fellows/. If you would like to nominate someone to be a PSF Fellow, please send a description of their Python accomplishments and their email address to psf-fellow at python.org. Quarter 2 nominations are currently in review. We are accepting nominations for Quarter 3 through August 20, 2024.

Are you a PSF Fellow and want to help the Work Group review nominations? Contact us at psf-fellow at python.org.

August 13, 2024 02:20 PM UTC


Real Python

Sorting Dictionaries in Python: Keys, Values, and More

You’ve got a dictionary, but you’d like to sort the key-value pairs. Perhaps you’ve tried passing a dictionary to the sorted() function but didn’t receive the results you expected. In this video course, you’ll go over everything you need to know to sort dictionaries in Python.

In this video course, you’ll:


[ 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 ]

August 13, 2024 02:00 PM UTC


Stefanie Molin

How Pre-Commit Works

So, you've just set up pre-commit hooks on your repository using `pre-commit`, but do you know what actually happened when you ran `pre-commit install` or why you had to run it in the first place? How does `pre-commit` actually work with Git? In this article, I will take you behind the scenes of how your `pre-commit` setup works.

August 13, 2024 01:51 PM UTC


Python Bytes

#396 uv-ing your way to Python

<strong>Topics covered in this episode:</strong><br> <ul> <li><a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"><strong>uv venv</strong></a><a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"> </a><a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"><strong>--python</strong></a><a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"> <strong>&amp; uv python</strong></a></li> <li><strong><a href="https://docs.python.org/release/3.12.5/whatsnew/changelog.html#python-3-12-5">Python 3.12.5 released</a></strong></li> <li><strong><a href="https://blog.rxbc.se/posts/compile-and-use-dependencies-for-multiple-python-versions-in-tox/?featured_on=pythonbytes">Compile and use dependencies for multiple Python versions in Tox</a></strong></li> <li><strong><a href="https://hallofshame.design/collection/?featured_on=pythonbytes">Catalog of Dark Patterns</a></strong></li> <li><strong>Extras</strong></li> <li><strong>Joke</strong></li> </ul><a href='https://www.youtube.com/watch?v=0Sa0z2XXwwk' style='font-weight: bold;'data-umami-event="Livestream-Past" data-umami-event-episode="396">Watch on YouTube</a><br> <p><strong>About the show</strong></p> <p>Sponsored by ScoutAPM: <a href="https://pythonbytes.fm/scout"><strong>pythonbytes.fm/scout</strong></a></p> <p><strong>Connect with the hosts</strong></p> <ul> <li>Michael: <a href="https://fosstodon.org/@mkennedy"><strong>@mkennedy@fosstodon.org</strong></a></li> <li>Brian: <a href="https://fosstodon.org/@brianokken"><strong>@brianokken@fosstodon.org</strong></a></li> <li>Show: <a href="https://fosstodon.org/@pythonbytes"><strong>@pythonbytes@fosstodon.org</strong></a></li> </ul> <p>Join us on YouTube at <a href="https://pythonbytes.fm/stream/live"><strong>pythonbytes.fm/live</strong></a> to be part of the audience. Usually Tuesdays at 10am PT. Older video versions available there too.</p> <p>Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to <a href="https://pythonbytes.fm/friends-of-the-show">our friends of the show list</a>, we'll never share it. </p> <p><strong>Brian #1:</strong> <a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"><strong>uv venv</strong></a><a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"> </a><a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"><strong>--python</strong></a><a href="https://github.com/astral-sh/uv/blob/0.2.35/docs/concepts/python-versions.md?featured_on=pythonbytes"> <strong>&amp; uv python</strong></a></p> <ul> <li>I was reading this article <a href="https://dev.to/astrojuanlu/python-packaging-is-great-now-uv-is-all-you-need-4i2d?featured_on=pythonbytes">Python Packaging is Great Now:</a><a href="https://dev.to/astrojuanlu/python-packaging-is-great-now-uv-is-all-you-need-4i2d?utm_source=pocket_shared&featured_on=pythonbytes"> </a><a href="https://dev.to/astrojuanlu/python-packaging-is-great-now-uv-is-all-you-need-4i2d?utm_source=pocket_shared&featured_on=pythonbytes"><code>uv</code></a><a href="https://dev.to/astrojuanlu/python-packaging-is-great-now-uv-is-all-you-need-4i2d?utm_source=pocket_shared&featured_on=pythonbytes"> is all you need</a></li> <li>It’s a little too “look, a silver bullet” for me, but it did point out some cool uv stuff I didn’t know about. <ul> <li>uv venv venv --python 3.12 creates a virtual environment with Python 3.12, <ul> <li>even if you didn’t have 3.12 installed on your system already.</li> <li>If it doesn’t work, try adding --python-preference managed</li> </ul></li> <li>uv python list shows all the python versions on your computer</li> <li>There’s quite a few “experimental features” <ul> <li><strong>run</strong> Run a command or script (experimental)</li> <li><strong>init</strong> Create a new project (experimental)</li> <li><strong>add</strong> Add dependencies to the project (experimental)</li> <li><strong>remove</strong> Remove dependencies from the project (experimental)</li> <li><strong>sync</strong> Update the project's environment (experimental)</li> <li><strong>lock</strong> Update the project's lockfile (experimental)</li> <li><strong>tree</strong> Display the project's dependency tree (experimental)</li> <li><strong>tool</strong> Run and manage tools provided by Python packages (experimental)</li> <li><strong>python</strong> Manage Python versions and installations (experimental)</li> </ul></li> </ul></li> <li>uv add --dev pytest will add pytest to your dev dependencies.</li> <li>uv tree rocks</li> <li>uv might not have “solved packaging” (or maybe it might have) <ul> <li>but it sure is fun to watch the experimentation of different workflows.</li> </ul></li> </ul> <p><strong>Michael #2:</strong> <a href="https://docs.python.org/release/3.12.5/whatsnew/changelog.html#python-3-12-5">Python 3.12.5 released</a></p> <ul> <li>Lots of changes, see the <a href="https://docs.python.org/release/3.12.5/whatsnew/changelog.html#python-3-12-5">release notes</a></li> </ul> <p><strong>Brian #3:</strong> <a href="https://blog.rxbc.se/posts/compile-and-use-dependencies-for-multiple-python-versions-in-tox/?featured_on=pythonbytes">Compile and use dependencies for multiple Python versions in Tox</a></p> <ul> <li>Viktor Rimark</li> <li>Cool idea to use the {envname}, which specifies the tox environment, in the name of a requirements-dev.txt file name.</li> <li>Then add a requirements tox target to generate pip-compile-ed files.</li> <li>Now I gotta try doing all of this with uv lock</li> <li>Then we need everyone to mod their tools to comply with <a href="https://peps.python.org/pep-0751/?featured_on=pythonbytes">PEP 571</a>, when/if it’s adopted (covered it last week)</li> </ul> <p><strong>Michael #4:</strong> <a href="https://hallofshame.design/collection/?featured_on=pythonbytes">Catalog of Dark Patterns</a></p> <ul> <li>Including <ul> <li>Bait and Switch</li> <li>Confirm Shaming</li> <li>Disguised Ads</li> <li>Roach Motel</li> <li>Fake Scarcity</li> <li>…</li> </ul></li> </ul> <p><strong>Extras</strong> </p> <p>Brian:</p> <ul> <li>Recording of <a href="https://courses.pythontest.com/hello-pytest?featured_on=pythonbytes">Hello, pytest!</a> is done. Editing now. On track for the 19th (or before).</li> </ul> <p>Michael:</p> <ul> <li><a href="https://www.djangoproject.com/weblog/2024/aug/07/django-51-released/?featured_on=pythonbytes">Django 5.1</a> released</li> <li><a href="https://blog.python.org/2024/08/python-3130-release-candidate-1-released.html?featured_on=pythonbytes">Python 3.13.0 release candidate 1</a> released</li> </ul> <p><strong>Joke:</strong> </p> <ul> <li><a href="https://clownstrike.lol/?featured_on=pythonbytes">clownstrike</a> <ul> <li><a href="https://arstechnica.com/tech-policy/2024/08/parody-site-clownstrike-refused-to-bow-to-crowdstrikes-bogus-dmca-takedown?featured_on=pythonbytes">ARS Technica article on DMCA for ClownStrike</a></li> </ul></li> </ul>

August 13, 2024 08:00 AM UTC

August 12, 2024


PyCharm

PyCharm 2024.2 Is Here: Improvements for Jupyter Notebooks, Databricks Integration, New AI Assistant Features, and More!

Offering a wide range of new and improved functionality, including Hugging Face integration, new AI Assistant features, a new default UI, and an overall better user experience, PyCharm 2024.2 is a must for anyone looking to increase their productivity. 

Learn about all the updates on our What’s New page, download the latest version from our website, or update your current version through our free Toolbox App.

PyCharm 2024.2

PyCharm 2024.2 key features

Databricks integration PRO

PyCharm now provides direct integration with Databricks via a plugin. You can connect to a Databricks cluster, execute scripts and notebooks as workflows, execute files directly in a Spark shell on a cluster, and monitor the progress – all from the comfort of your IDE.

PyCharm Databricks

This integration allows you to harness the power of your IDE when working with Databricks, making the process faster and easier. 

Hugging Face integration PRO

PyCharm 2024.2 can now suggest the most relevant Hugging Face models based on your use case. When you select a model, the IDE will suggest inserting a code snippet that allows you to use it directly in the open file, and PyCharm will download and install any missing dependencies automatically.

PyCharm Hugging Face

You can also identify unused models installed on your machine and delete them to free up disk space directly from the IDE. 

Additionally, you can inspect your Hugging Face Datasets library data as an interactive dataframe, utilizing features like the chart view, pagination, and the ability to sort and export tables.

Jupyter notebooks PRO

Instantly preview the value of a chosen variable simply by hovering over the variable’s line. You no longer need to use the debugger or print statements!

Furthermore, you can now expand and collapse cells, as well as run them straight from the gutter. Additionally, cells now display their statuses and assigned tags.

All these improvements are designed to make working with Jupyter notebooks in PyCharm seamless, fast, and efficient. 

PyCharm Jupyter Notebooks

AI cells in Jupyter notebooks

With our new AI cell option, you can add prompts directly inside your notebooks and work with AI Assistant right from there. A light bulb icon next to the AI cell provides suggestions about the next steps in your data analysis workflow.

One-click dataframe visualization

Visualize your dataframes with the help of AI Assistant, which now provides suggestions about the graphs and plots most suitable to your context.

AI Assistant

JetBrains AI Assistant 2024.2 enhances cloud-based code completion with faster, more accurate suggestions and a better UX, including syntax highlighting and the option to accept suggestions incrementally. The AI chat now uses the latest GPT-4o model and supports chat references and semantic search. 

New features include AI integration in the Terminal tool window for command generation, AI-assisted VCS conflict resolution, and customizable prompts for documentation and unit test creation.

Learn about these and other AI Assistant enhancements in this dedicated blog post.

AI assistant

Database tools PRO

New AI Assistant features 

With the text-to-SQL feature, you can generate SQL code directly in the editor by clicking Generate Code with AI and entering your prompt. You can accept, regenerate, or refine the code, and take it to the AI chat if you have further questions.

Additionally, AI Assistant can help with modifying tables, allowing you to request changes like switching all VARCHAR data types to CHAR.

It can also help you understand and fix SQL problems, suggesting explanations and fixes. 

User experience

Preview option in Search Everywhere

The Search Everywhere dialog now includes an option to preview the codebase elements you’re searching for, offering additional context and making it easier to navigate through your project.

Improved full line code completion PRO

In 2024.2, full line code completion suggestions now include code highlighting, and new shortcuts allow you to accept individual words or entire lines from longer suggestions. We’ve also refined how accepted changes are integrated into your code, eliminating any formatting issues.

Run/Debug

String variable visualizers for JSON, XML, and other formats

Debugging and browsing long string variables with complex data formats is now much easier. The updated debugger offers properly formatted visualizations for string variables with strings encoded in JSON, XML, HTML, JWT, and URL.

Frameworks and technologies PRO

GraalJS as the execution engine for the HTTP Client 

We’ve upgraded the JavaScript execution engine used in the HTTP Client to GraalJS. This allows you to use all GraalJS features, including full support for the ECMAScript 2023 specification, when testing endpoints with PyCharm’s HTTP Client and using JavaScript in .http files to handle the results.

HTTP Client improvements

In the HTTP Client, we’ve added XPath functionality for querying and manipulating XML and HTML documents, support for iterating through collections using JSONPath to automate requests, and the ability to create and add custom API methods effortlessly. 

Enhanced Terraform support 

We’ve enhanced PyCharm’s Terraform support with full line code completion, improved context-aware code completion, refined syntax highlighting, and better error detection with quick-fix suggestions. Additionally, a quick documentation feature now provides instant tooltips, offering immediate information to streamline your Terraform workflow.

Frontend PRO

Improved support for major web frameworks

PyCharm can now resolve paths for frameworks that use file-system-based routing. It can also resolve link paths based on your project’s file system, providing autocompletion and navigation for Next.js, Nuxt, SvelteKit, and Astro. There is also support for new Svelte 5 snippets and render tags. 

Additionally, we’ve implemented language server protocol (LSP) support for Astro and upgraded the Vue LSP to Vue Language Service v2, improving code completion and the overall developer experience.

Ability to run and debug TypeScript files directly

You can now run and debug TypeScript files from different entry points, including the file context menu, the Run widget, and the Current File configuration. 

Remote development PRO

Reverse port forwarding

With reverse port forwarding, you can now connect a remote IDE to ports available on the client machine. This is particularly useful for mobile development and connecting to local databases.

These are all the key features of this release, but there’s much more to explore! Visit our What’s New page or release notes for the full breakdown and additional details about the features mentioned here. 

If you encounter any problems, please report them in our issue tracker so we can address them promptly. 

Connect with us on X (formerly Twitter) to share your thoughts on PyCharm 2024.2. We’re looking forward to hearing them!

August 12, 2024 02:06 PM UTC


Real Python

Python News Roundup: August 2024

In July, there was some exciting news for the Python community as the Python core development team released versions 3.13.0b4 and 3.13.0rc1 of the language. The 3.13.0b4 release marked the end of the beta phase and paved the way for the release candidate phase.

Note that 3.13.0rc1 is a pre-release, so you shouldn’t use it for production environments. However, it provides a great way to try some new and exciting language features.

There’s also great some news from the Python Software Foundation, PyOhio 2024, and the Python ecosystem.

Let’s dive into the most exciting Python news from last month!

Python 3.13.0b4 and 3.13.0rc1

Python 3.13 has reached its fourth beta release, marking the end of the beta phase. Beta releases serve to test new features and bug fixes. However, it’s important to note that this is a preview release and it isn’t recommended for use in production environments.

If you’re a library maintainer, you’re encouraged to test your code with this new version so you can prepare it to support the latest features of the language.

Note: To learn more about pre-releases, check out the How Can You Install a Pre-Release Version of Python? tutorial.

One of the most significant new features of Python 3.13 is the improved interactive interpreter or REPL, which now provides several cool features, including:

  • Colorized prompts
  • Multiline editing with history preservation
  • Interactive help browsing with F1 and a separate command history
  • History browsing with F2
  • Paste mode for larger blocks of code with F3
  • REPL-specific commands like help, exit, and quit without the call parentheses

This is exciting news! The standard REPL up until Python 3.13 was lacking, and sometimes it was necessary to install a third-party tool like bpython or IPython to compensate.

Again, with this release, the beta phase has officially ended, and the first release candidate—3.13.0rc1—is considered the penultimate release preview. In this release candidate phase, only bug fixes are allowed.

The second candidate, which is the last planned release preview, should be out on September 3, 2024, and the official release of 3.13 should be ready on October 1, 2024. Only more excitement lies ahead!

The Python Software Foundation (PSF) Shares Great News

Read the full article at https://realpython.com/python-news-august-2024/ »


[ 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 ]

August 12, 2024 02:00 PM UTC


Mike Driscoll

Creating Progress Bars in Your Terminal with Python and Textual

The Textual package is a great way to create GUI-like applications with Python in your terminal. These are known as text-based user interfaces or TUIs. Textual has many different widgets built-in to the framework.

One of those widgets is the ProgressBar. If you need to show the progress of a download or long-running process, then you will probably want to use a progress bar or some kind of spinner widget to show the user that your application is working.

This tutorial will show you how to create a simple progress bar with Textual!

Installation

If you do not have Textual installed yet, you can get it by using Python’s handy pip tool. Open up your terminal and run the following command there:

python -m pip install textual

Textual will get installed, along with all its dependencies. You may want to create a virtual environment first and install Textual there.

Creating a ProgressBar in Textual

Creating a progress bar with Textual is pretty straightforward. The following code is based on an example from the Textual documentation. The main difference is that this version uses a button to start the timer, simulating a download or some other long-running process rather than catching a key event.

You can copy this code into your favorite Python editor and give it a quick study:

# progressbar_demo.py

from textual.app import App, ComposeResult
from textual.containers import Center, Middle
from textual.timer import Timer
from textual.widgets import Button, ProgressBar

class Progress(App[None]):
    timer = Timer

    def compose(self) -> ComposeResult:
        with Center():
            with Middle():
                yield ProgressBar()
                yield Button("Start")

    def on_mount(self) -> None:
        """
        Set up the timer to simulate progress
        """
        self.timer = self.set_interval(1 / 10, self.advance_progressbar, pause=True)

    def advance_progressbar(self) -> None:
        """
        Called to advance the progress bar
        """
        self.query_one(ProgressBar).advance(1)

    def on_button_pressed(self) -> None:
        """
        Event handler that is called when button is pressed
        """
        self.query_one(ProgressBar).update(total=100)
        self.timer.resume()

if __name__ == "__main__":
    app = Progress()
    app.run()

The compose() method is kind of fun as it uses both the Center() and the Middle() containers to position the widgets in the middle of the terminal. You then set up the timer object in on_mount() and you start the timer in on_button_pressed()which is the Button widget’s event handler.

When you run this code, you will initially see what’s known as an indeterminate progress bar. What that means is that Textual doesn’t have any information about how long the progress is, so the progress bar just shows a kind of “bouncing” or “cycling” progress:

When you press the “Start” button, you will see the progress bar go from 0-100%, and the text fields to the right will update as well:

If you want to make your progress bar stand out, add a gradient. A gradient will make the colors of the progress bar change over time and make the widget look neat!

Wrapping Up

Adding a progress bar or simply showing some kind of informational widget that lets the user know your application is working is always a good idea. You don’t want the user to think the application has crashed or frozen. The user might be forced to close the application and lose their information after all!

Fortunately, Textual makes adding a progress bar easy. Not only is it easy, but the progress bar is easy to update so you can accurately give the user a sense of when the work will be done. Give it a try and see what you think!

Related Reading

Want to learn more about Textual? Check out the following articles:

The post Creating Progress Bars in Your Terminal with Python and Textual appeared first on Mouse Vs Python.

August 12, 2024 12:21 PM UTC