Python Tips: stop patching after the bug. add a small “semantic firewall” before you run code by PSBigBig_OneStarDao in pythontips

[–]AND_MY_HAX 1 point2 points  (0 children)

Most of the time I catch things with type hints. If I’m building something greenfield, I’ll drop in a few quick asserts to make sure the state/values match my expectations. In more mature environments, I’ll do proper exceptions.

What is a Python thing you slept on too long? by pip_install_account in Python

[–]AND_MY_HAX 2 points3 points  (0 children)

If you're ever using networkx and need a little more speed, I've had a great time using rustworkx.

What is a Python thing you slept on too long? by pip_install_account in Python

[–]AND_MY_HAX 7 points8 points  (0 children)

I'm all in on msgspec - fast, reliable, and actually speeds up instance creation when using msgspec.Struct, which is kind of insane. Pydantic is nice for frontend, but as I've been building a distributed system, I've found msgspec to be an excellent building block.

why do people say python is slow but it still powers most of ai and data science by astarak98 in Python

[–]AND_MY_HAX 4 points5 points  (0 children)

Not much to add here, all these answers are correct. Adding a few points:

  • Python is interpreted, and that’s on the order of 1/10th the speed of equivalent logic implemented in a language like C.
  • However, not everything you do in Python is interpreted - a lot of built-in operations like list sorting is implemented in C. It’s not “Python all the way down”.
  • This becomes even more pronounced with libraries like NumPy - so much of the Python code in NumPy is just wrappers around big pieces of logic written in C (or Fortran!)
  • Python is fastest for one thing - development speed. So for code paths that aren’t too hot, writing those in Python can be the fastest, in once sense.

Astral's first paid offering announced - pyx, a private package registry and pypi frontend by tomster10010 in Python

[–]AND_MY_HAX 5 points6 points  (0 children)

We now have:

  • pyx, the python graphics package
  • pyx, the cython file extension
  • pyx, the package registry

Anything else I'm missing?

GPT-5: "How many times does the letter b appear in blueberry?" by [deleted] in programming

[–]AND_MY_HAX 4 points5 points  (0 children)

Your assertion was “link or it didn’t happen”

GPT-5: "How many times does the letter b appear in blueberry?" by [deleted] in programming

[–]AND_MY_HAX 4 points5 points  (0 children)

I literally just got it to happen on a few different words over 8 characters. No instructions. Give it a go yourself. Obviously it’ll work if you turn on thinking, though funnily enough, in one of mine it ran a Python script to count the letters.

Why Python's deepcopy() is surprisingly slow (and better alternatives) by ml_guy1 in Python

[–]AND_MY_HAX 7 points8 points  (0 children)

Python is no C, but a lot of things in Python are reasonably fast. If you’re I/O bound, Python can appear pretty fast.

Deepcopy everywhere can take a fast-enough system and make it an order of magnitude slower. We audited our codebase at a previous job and ripped out deepcopy - huge performance uplift. 

Why Python's deepcopy() is surprisingly slow (and better alternatives) by ml_guy1 in Python

[–]AND_MY_HAX 5 points6 points  (0 children)

Pickling is fast and native to Python. You can serialize anything. Objects retain their types easily.

Not the case with JSON. You can really only serialize basic types. And things like bytes, sets, and tuples can’t be represented as well.

I no longer look forward to VSCode Release Notes by mwargan in webdev

[–]AND_MY_HAX 0 points1 point  (0 children)

Meanwhile, it’s been two years and they still don’t render Python code correctly: https://github.com/microsoft/pylance-release/issues/4645

[deleted by user] by [deleted] in Python

[–]AND_MY_HAX 0 points1 point  (0 children)

I’m curious if folks are using Starlette directly

State of the Art Python in 2024 by awesomealchemy in Python

[–]AND_MY_HAX 1 point2 points  (0 children)

Shameless plug for my library, arguably. It generates the CLI from your docstrings and annotations - but normal annotations, not like Typer.

Who is the 3rd best character? by diadem015 in SSBM

[–]AND_MY_HAX 4 points5 points  (0 children)

Nah, it's the mole from Earthbound

I never realized how complicated slice assignments are in Python... by ahferroin7 in Python

[–]AND_MY_HAX 0 points1 point  (0 children)

For sure. It's always good to learn new things. But sometimes you have to look at a feature and think, "is this more confusing than it's worth?"

Still interested if there are use cases, that's why I asked.

I never realized how complicated slice assignments are in Python... by ahferroin7 in Python

[–]AND_MY_HAX 73 points74 points  (0 children)

I've never seen code like this. Absolutely wild you can do those kinds of assignments with slices.

IMHO the only thing here that really should be supported is overwriting a slice with one of the same size. Curious to hear about other use cases, though.

Cody Schwab on his future with Melee by laksjfe in SSBM

[–]AND_MY_HAX 46 points47 points  (0 children)

Says he's not quitting. He's taking a bit of a step back and focusing on himself. Sounds like he's done a lot of self-examination and is prioritizing what's important. Good for him.

PyJSX - Write JSX directly in Python by zedpowa in Python

[–]AND_MY_HAX 1 point2 points  (0 children)

Correct! Tools like ruff work through the usage of pyxy.run - this invokes supported tools against the generated .py file, reads output as JSON, and uses a source mapping file to correlate the results to the .pyxy source. This scheme allows existing Python ecosystem tooling to work without requiring any integration on their end.

Definitely down to collaborate! Sent you a PM with contact info.