Live data from Hacker News

What new Python features are the most useful for you?

news.ycombinator.com

31–40 of 44 posts

Re: What new Python features are the most useful for you?

#31
post #2

- einops (probably by far the most useful Python dsl for me as of late, esp. if you deal a lot with tensors) - numpy __array__ interface standardization (easy compatibility across a lot of numerical libraries, e.g. torch, awkward-array, zarr, jax.numpy, dask, xarray) - the various jit compilers (e.g. numba, jax.jit, torch.compile) - hw-accelerated functional programming style (e.g. functorch.vmap) - pybind11 for easy…

I had checked out plotly some years ago:

plot.ly now has an API:

https://jugad2.blogspot.com/2013/07/plotly-now-has-api.html

Re: What new Python features are the most useful for you?

#32
post #27

Earlier quoted context omitted.

That is my point. I don't have any tools to prevent it from happening. I just don't do it when I write the code. If I have and my code is tested it comes up very quickly. Us older people tend to keep the whole workflow as simple as possible. That is why I love python. There is very little overhead to just using it. If you tend to make this mistake a lot it might make sense to add some tooling. I don't need it. If I w…

I think you're either misrepresenting reality or stretching the truth. For example, if you're redefining bug as "bug that made it past testing" that's one thing. But I don't buy anyone writing Python daily for 15 years hasn't seen the term "TypeError" which is what your previous two comments were implying.

OK, it's 100% likely I saw it, just so rarely I can't remember.

Testing. Over that long time I have used many test frameworks. My normal workflow is to try and exercise all the code I write as I go.

On the other hand I am 100% pedantic about using 'schema' (https://pypi.org/project/schema/) to validate all the types, structure and domains when I read json.

Re: What new Python features are the most useful for you?

#33
post #2

- einops (probably by far the most useful Python dsl for me as of late, esp. if you deal a lot with tensors) - numpy __array__ interface standardization (easy compatibility across a lot of numerical libraries, e.g. torch, awkward-array, zarr, jax.numpy, dask, xarray) - the various jit compilers (e.g. numba, jax.jit, torch.compile) - hw-accelerated functional programming style (e.g. functorch.vmap) - pybind11 for easy…

plotnine is an API based on Grammar on Graphics. I use it as an replacement for matplotlib.

Re: What new Python features are the most useful for you?

#34
post #20
post #16

Earlier quoted context omitted.

Why use Pydantic instead of dataclasses?

Pydantic can do validation. There’s also the related Typer, which builds command line interfaces from the type annotations on your entry point

You might also want to look at https://www.attrs.org, which is basically what dataclasses were supposed to be.

Re: What new Python features are the most useful for you?

#35
post #6

The `click` library would be a nice replacement to `argparse`

Which is fine when building a complex CLI tool which requires other external libraries; but otherwise the compexity of argparse is simply not significant enough to justify the cost of adding external dependencies.

Re: What new Python features are the most useful for you?

#36

The lack of boilerplate. Low ceremony. Just write the code, save the file and run it. That in itself is a great feature.

But all the other files, and the dependencies, and where is it going to run, and does it have permissions to see all the data and account resources it needs, and the testing, and...

Re: What new Python features are the most useful for you?

#37
post #27

Earlier quoted context omitted.

I guess I meant what do you do to prevent that from happening.

That is my point. I don't have any tools to prevent it from happening. I just don't do it when I write the code. If I have and my code is tested it comes up very quickly. Us older people tend to keep the whole workflow as simple as possible. That is why I love python. There is very little overhead to just using it. If you tend to make this mistake a lot it might make sense to add some tooling. I don't need it. If I w…

You do get type errors, but you catch them with tests? Type hinting catches them without having to write tests.

Re: What new Python features are the most useful for you?

#38
post #32

Earlier quoted context omitted.

I think you're either misrepresenting reality or stretching the truth. For example, if you're redefining bug as "bug that made it past testing" that's one thing. But I don't buy anyone writing Python daily for 15 years hasn't seen the term "TypeError" which is what your previous two comments were implying.

OK, it's 100% likely I saw it, just so rarely I can't remember. Testing. Over that long time I have used many test frameworks. My normal workflow is to try and exercise all the code I write as I go. On the other hand I am 100% pedantic about using 'schema' ( https://pypi.org/project/schema/ ) to validate all the types, structure and domains when I read json.

Nearly the same here. The only type error I make a little bit more than I would like, is expecting an iterable and passing a string instead, because I forgot parentheses around arguments.

But I made way more type errors when programming in C/++.

Why do you prefer schema to (fast)jsonschema?

Re: What new Python features are the most useful for you?

#39
Most used: f-Strings Second: pattern matching and dataclasses

If I ever could wrap my brain around asyncio, it would be an appreciated third.

I never used the walrus operator, IIRC, and I find type hints not so useful. Somewhere in the future I will try to use them in APIs, they may have their benefit there.

Edit: I forgot enums. Not so new, but a must.

Post reply on HN