Show more

Latest @pythonbytes episode is out with your #python news, just in time for your holiday travel:

#311: Catching Memory Leaks with ... pytest?

By @brianokken and @mkennedy + special guest @murilocunha

— Code Wars: Episode IV – The Language Wars —

Which is better? Java or Python or Javascript or C++ or Rust or Julia or …

You often see the language wars being waged on many fronts – books, online tutorials, and of course here on social media

Each language has its pros & cons, strengths & weaknesses

The reason there isn’t one language to rule them all (I’m mixing my fictional references!) is because all have or had a place

The language that’s best for one purpose may not be the ideal for another

Where do I stand on this?

Although you only ever see me post about Python, and all my current work is in Python, you may (or may not) be surprised to know that I won’t participate in this feud

Yes, I think Python is a brilliant language – and lots has been written elsewhere about this

But the “language A is better than language B” argument or the “language Z is rubbish” line doesn’t lead to anything fruitful. Ever!

So these childish debates are not for me, sorry!

Think of the programming language as a tool to achieve your objective. What matters is achieving your objective and not which tools you use

Of course, some tools are more suited for certain objectives…

On the other hand, if you know how to use one particular tool very well and want to use it for most of your tasks, there’s nothing too wrong about that, either!

Coming Soon: Code Wars Episode V

As I’ve been re-watching the Star Wars trilogy of trilogies (kids are now interested, so I’m doing it for them!), I thought of creating a Code Wars series – where are the battles relating to programming fought?

So, we start with Episode IV, of course. Here it comes…

I’m still surprised at how many hits this article gets every day, so let me reshare it here in case it’s of interest to anyone.

It’s rather niche, but it’s a fun tutorial to follow even if it’s not really your field:

Recreating any image from sines and cosines

Hey #introduction, I am a software developer and coach.

I love building practical tools that make other people's lives easier.

And I am passionate about helping people build their Python, developer and mindset skills to succeed in their tech careers.

I do this via Pybites, which I co-founded back in 2016 with Julian Sequeira (hope he joins me here soon haha ...)

Teaching #Python and interested in adding physical computing? Or using the BBC #microbit in class and wanting to explore text-based coding? I'm co-hosting two more webinars this month on the new micro:bit Python Editor.
It's designed to overcome barriers to learning with a simulator, reference section with code snippets you can drag and drop into your code, auto-complete, indentation highlighting and more.
Webinar details here:

Do you know the offside rule? Sure? To have some fun, I’m writing a quiz using Python’s turtle

This is what it looks like so far (and no, I’m not bothering with fancy graphics – life’s too short)

In this video:

  • you can see direction in which team is attacking from the arrows
  • each snapshot shows when player with the ball kicks the ball forward
  • program (hopefully) detects whether it’s offside or not
  • there are 15 (random) scenarios in this video

Still to do:

  • deal with when forward player is in own half (no offside)
  • deal with when forward player is the one with the ball (no offside)
  • turn into a quiz
  • write article for The Python Coding Book blog about it to document the code - there are some interesting aspects I’m using in the code that hopefully some will find useful.

Weird Python line of the day:

>>> [10, 20, 15, 12, 9][_]
[20, 15]

How can you achieve this?

Note: this is not something you’ll want to do in real code, just a Python curiosity!

Work in progress - An Offside Rule Quiz using Python’s turtle

Will aim to get it done in the next few days… (will write it up as an article, too)

For those who don’t follow football (that’s soccer for some around the world), the offside rule is one of those “notorious” rules that not everyone gets.

This is a great resource for teachers who are eager to teach Python. Teaching Python #python #edutooter #edtech @edutooters

There are often heated arguments, often with many holding “absolutist” positions, on various topics in . However, as with other areas of life, it’s the more nuanced pragmatic view that (should) prevail.

Let’s take static and dynamic typing. There are reasons why not all leading languages use either one or the other. They’re different tools for different jobs.

If you need to prioritise safety in production code: static typing may be your choice.

If you want to prioritise prototyping speed and writing code rapidly, including by programmers who don’t just program but use coding as part of other professional skills, dynamic typing options may be better.

It’s all about using the right mindset for the right language. If someone is used to coding in C++, say, and tries to write Python code in the same way they write C++, that can (and will) lead to problems! The same is true the other way round, too, of course.

Take duck typing in languages such as : that’s a mindset–prioritising what an object can do rather than what it is. Once you get it, and you think about whether something is a sequence or an iterator rather than a list or string, say, then you’re better placed to code in Python

There’s no “this is the better one”, instead, there’s “this is the better one for this application”

One of my (many) 2023 plans is to add finishing touches to and make it available in some other format, too:

  • ebook only
  • self-published book
  • published via a publisher

My preference is the latter but publishers shy away from beginners’ books…

I’d need to spend time carefully pitching to them why I think it’s different from other books. Not sure I can justify time to do that

More thinking needed

In the meantime, the content is all there for beginners to enjoy, and many have done just that

One thing that many find very confusing when they first learn about generators is that once they’re exhausted they’re, erm, exhausted.


Let’s see what this means with an example. Let’s start with a list, first:

numbers = [item for item in range(10)]

# Loop through numbers
for number in numbers:

# And let's loop one more time…
for number in numbers:

We’ve used a list comprehension to create a list of numbers–it’s not the most exciting list you’ll see, but it will do here

You’re them looping through the list twice, printing out the values each time

Here’s the output from this code:


I did say it’s not an exciting list. I know!

The numbers are printed out twice. Of course they are, since you’ve repeated the loop twice

Let’s see what happens with a generator instead of a list:

# Notice that we've now made this a generator
numbers = (item for item in range(10))

# Loop through numbers
for number in numbers:

# And let's loop one more time…
for number in numbers:

Notice how we’re now using parentheses (round brackets) instead of square brackets when creating numbers

This creates a generator

If you print(type(numbers)) you’ll get:
<class 'generator'>

and if you print(numbers):
<generator object <genexpr> at 0x103309ff0>

So, what’s the output from the two for loops?

Let’s find out:


The numbers are only printed out once. The generator was “used up” when you looped through it the first time, so you can’t use it again

Here’s why this happens (very abridged version):

A generator doesn’t store the data within it. Instead, it refers to data which is stored or created elsewhere

So, when you try and fetch the first item in numbers, the generator fetches 0 and it now “knows” it’s taken the first value…

So the next time you need a value from numbers, it will get the second one, and so on…

Once it fetches the last item, there’s nothing left
The generator is exhausted
When you try to fetch another item, there’s nothing there

Think of a generator as single-use

Today for #projects: another hashtag I coined, the #pythonoddity hashtag.

Years ago I decided I was going to try tweeting one "python oddity" (anything that might be a gotcha for a new Python user). I decided to make a hashtag for it: #pythonoddity.

I still collect #python oddities but I don't share them as regularly as I used to. Maybe I should start that hashtag up again here?

Here's a collection of some of my favorite #pythonoddity tweets over the years:

I was rewatching Star Wars recently (kids are now interested) and it reminded me of (tenuous link warning!) when I decided to explore __copy__() in Python and dive a bit deeper

Copy->Clones->Storm Troopers->there’s the tenuous link

Anyway, here’s the article for those interested - note the image with Lego storm troopers has been there since I published this article!

Some more tree behaviours.

Clicking a node to move the cursor now works.

Labels can now have a 'icon' used to show expand state. You call set allow_expand=False for leaf nodes.

This core functionality will for the base of a tree control to browse a directory.

#textualtree #python

A (lengthy) Mastodon #introduction.

I'm Thomas, a Python Core Developer and Googler from Amsterdam (NL). I'm on the Python Steering Council and the #PSF Board of Directors, and I'm the 3.12/3.13 Release Manager. I hang out on #python on libera (IRC) as well. I also have #cats (#Savannah and #Bengal).

I usually toot/boost about #python, especially #governance and non-profit support of #python. A little thread with examples (and cat pictures at the end)👇

Why is Python the ideal language for beginners to learn?

Let's look at the main reasons:

• It's more accessible for a beginner, allowing you to focus on programming concepts and not language detail. Too many give up coding early on–Python makes this less likely

• It's very powerful–which means you can write any program you'll need and it scales well as you deal with more complex programs and larger data sets

• It's very broad–it has applications in very many fields and not just a narrow scope. It also has libraries for very many fields!

• As it's very popular, it has a large user-base which is very helpful, so you'll find a lot of resources (not just mine!) and a lot of help from the community

• It's a language that's still improving and progressing rapidly. Latest speed improvements is just one example


The main thing you're learning is programming, and not a programming language. The language itself is "just" a tool, but you don't want the tool to get in the way of learning, as would happen with some other languages.

Once you become proficient in programming in one language, it's easier to switch to/learn other languages

So my advice is, yes, start with Python and stick with it until you feel you're very proficient. If and when you need other languages, they'll be easier to learn then…

Thinking about where to set up the Teaching Python podcast on Mastodon. Any servers focused on education?

Hello everybody,

This is the page of the pandas project. There's a chance we may migrate to a purpose-built Scientific Python instance later, but for now we're here

Follow for news on releases, meetings, and on how to contribute!


Show more
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.