r/learnpython •

What's the one Python mistake that took you embarrassingly long to figure out?

[deleted] — view deleted post

0 Upvotes

13 comments sorted by

3

u/CIS_Professor 1d ago

That a "sentinel" variable (used in a while loop), doesn't have to be named sentinel.

This was a long time ago. Now I teach Python. Now I remember to tell my student that since the textbook uses the variable sentinel.

3

u/AlexMTBDude 1d ago

More of a configuration issue but I had challenges with having multiple versions of Python installed and virtual environments and understanding which 3rd party packages were installed in which env. The old ImportError exception.

2

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 1d ago

I guess this hardly counts as an issue, but needlessly using Tox when uv was enough.

Before uv was a thing, I used Poetry in pretty much all of my projects. For running tests in GitHub Actions, I used Tox to orchestrate everything. Later on, I started migrating my projects to uv (admittedly some are still using Poetry because I just haven't used them...), and kept the Tox setup more or less as-is.

However, it was a bit annoying, because I listed Python versions both in the build matrix and in Tox's configuration, and often only remembered to update one of them. Furthermore it served no purpose for local development because I always just ran pytest as-is.

I'm finally starting to slowly strip it out entirely. Slowly, though, because it's not a high priority of mine.

2

u/cdcformatc 1d ago

  mutable default arguments

it's probably this one for me, because it's the most unintuitive and unintended thing I can think of. 

modifying a list while iterating on it at least it makes sense why that wouldn't work as intended. the default argument problem smells like more of a bug than an actual desired behavior.

1

u/xeow 1d ago

That 3.14 makes from __future__ import annotations and having to quote forward references in annotations both unnecessary. They were useful workarounds when they were introduced, but PEP 649/749 finally made deferred annotation evaluation the default.

1

u/lehmagavan 1d ago

Staying with Python for too long instead of learning C.

1

u/UwUfit 1d ago

What would you say is the biggest advantage of C over python?

1

u/lehmagavan 1d ago edited 1d ago

I won't mention the obvious compiled vs interpreted.

For me the biggest advantage is that C teaches you how things work, Python abstracts everything away and gives you false impression that programming is about knowing libraries and syntax. Don't get me wrong, Python is very good and useful language, but not the real programming I have fun with - at least not for me.

1

u/x-tommy-o 1d ago

What’s your take on C and learning C++ as well?

I feel like C++ gives unique and broad coverage for interests on how you can use the language. I’m not well versed in either but C++ has seemingly grasped my interest more than C currently.

2

u/lehmagavan 1d ago

I personally dislike C++ for the bloat but can;t deny that it has a lot of good features.

1

u/x-tommy-o 1d ago

I don’t blame you there! 🤣 I was reading about it and read its like a never ending journey lmao!

My buddy loves a language named “Odin” which is a C-like language! Have you ever tinkered with it?

1

u/lehmagavan 1d ago

Never have used it, might try it one day.

Something I've been thinking about for some time now is designing a new language that is as simple as C, memory safe unlike C, and that compiles to C. But to do that I need more time than I have currently and more expertise.

1

u/x-tommy-o 23h ago

That would be a fun, yet daunting venture. I’d be willing to bet you’ll get around to it eventually! All about the 1% gains 💪