News for hackers. Stuff that matters.
Re:Understanding Python through its builtins by cinntaile on Sunday October 10, 2021 @12:29PM (#28819685)
Are there any good books that deal with writing pythonic code? As well as being focused on more intermediate or advanced features like this? If the book is project focused that's a bonus. Performance trade-offs another bonus.
Re:Understanding Python through its builtins by tusharsadhwani on Sunday October 10, 2021 @12:39PM (#28819760)
I can personally recommend Fluent Python (its 2nd edition is about to come out in a couple months) for learning these intermediate/advanced concepts, and Python Cookbook for code examples using many of these features.

I don't know any books for projects per-se, maybe HN will know!

Re:Understanding Python through its builtins by cinntaile on Monday October 11, 2021 @12:29AM (#28824679)
To me it looks like a lot of this knowledge is spread out over many different excellent technical blogs like yours. While the content is good, it's hard to get something that resembles a more complete picture compared to just another piece of a big puzzle.
Re:Understanding Python through its builtins by tracyhenry on Sunday October 10, 2021 @01:38PM (#28820315)
Searching python on HackerNews readings (a site I built): https://hacker-recommended-books.vercel.app/category/0/all-t... The results include Fluent Python recommended by tusharsadhwani
Re:Understanding Python through its builtins by disgruntledphd2 on Sunday October 10, 2021 @01:47PM (#28820418)
Fluent Python is definitely a good book, I knew a whole bunch of the stuff in this article because of it. I only got to Chapter 9, but it legitimately made my Python much, much better.
Re:Understanding Python through its builtins by asdfgeoff on Sunday October 17, 2021 @08:59AM (#28896141)
Not a book, but I have found Trey Hunner's https://www.pythonmorsels.com/ exercises very useful on this front.

The solutions presented typically include both a "basic" approach, a "as pythonic as possible" approach, and a brief discussion of the trade-offs between elegance and readability, etc.

Re:Understanding Python through its builtins by usrme on Sunday October 10, 2021 @02:29PM (#28820803)
I would recommend "Robust Python" by Patrick Viafore. It teaches you a lot about type annotations (among other thing) and gave me personally a whole new way of looking at the code that I write.
Re:Understanding Python through its builtins by cinntaile on Monday October 11, 2021 @12:26AM (#28824669)
Thanks for the different suggestions, I went with this one. Fluent Python also looked promising but I can't buy the 2nd ed yet.
Re:Understanding Python through its builtins by patviafore on Saturday October 16, 2021 @10:48PM (#28893522)
Author of Robust Python here: I definitely recommend Fluent Python as well once the 2nd edition is available. I wrote Robust Python to focus very much on how to write Python in a long-lived codebase and how to do trade-offs for readability/maintainability/testability/etc. It also covers a lot of things outside of standard built-ins (such as acceptance testing, mutation testing, pydantic, type checkers, etc.). I find Fluent Python to be more focused on more of the built-ins, and I think it might cover some of the performance trade-offs you might be looking for.

Long story short : I think both have a lot of value (but beware I'm quite biased on Robust Python)

Re:Understanding Python through its builtins by dehrmann on Sunday October 10, 2021 @01:40PM (#28820335)
In a way, learning Python is harder for people experienced with another language because so much of the content you find is for first-time programmers.

That said, I think I had good luck with Writing Idiomatic Python.

Re:Understanding Python through its builtins by matsemann on Sunday October 10, 2021 @02:30PM (#28820809)
Yes!

When I learned Kotlin, I just read through the docs, and then knew of basically all the different concepts in the language.

For Python, the docs were comparably very bad. For instance, Decorators aren't mentioned even once in the "The Python Tutorial". In "The Python Language Reference" (if one even bother to read such a dry document) it's barely mentioned in passing. How should a new user know it's a concept and how to apply it? And the language reference links only to a glossary item, and none of them specify how parameters in a decorator is supposed to work.

Pretty frustrating experience, put me a bit off the language from the get-go.

Re:Understanding Python through its builtins by tored on Sunday October 10, 2021 @05:43PM (#28822252)
As a non-Python dev I tried the other day to read up how decorators work in Python using the docs, can’t say it helped.
Re:Understanding Python through its builtins by pansa2 on Sunday October 10, 2021 @07:44PM (#28823000)
Decorators are very simple. I'm not surprised that there's not much documentation about them - there's just not much to say.

    @decorator
    def f(...): ...
is equivalent to:

    def f(...): ...
    f = decorator(f)
That's it.
Re:Understanding Python through its builtins by burnished on Monday October 11, 2021 @03:39PM (#28832122)
If you read the docs then you basically would not know about them. My experience mirrors the people upthread. I also found that the Python community is very hostile to the idea that the docs might be insufficient, in that people suggesting this in threads were frequently belittled or it was often suggested that the questant should just learn it like they did, or that it wasn't really all that hard.
Re:Understanding Python through its builtins by dehrmann on Monday October 11, 2021 @10:41PM (#28835504)
I've looked at a lot of Javadocs and Python docs. Python's docs leave a lot more up to the imagination and are generally harder to navigate around.

Compare their ThreadPoolExecutors (Python's being inspired by Java's)

https://docs.python.org/3/library/concurrent.futures.html#co...

https://docs.oracle.com/javase/7/docs/api/java/util/concurre...

Re:Understanding Python through its builtins by mattficke on Sunday October 10, 2021 @02:09PM (#28820623)
Effective Python [0] is my favorite book in this category.

[0] https://effectivepython.com/

Re:Understanding Python through its builtins by cinntaile on Tuesday October 12, 2021 @09:13PM (#28847109)
I'm giving this one a go as well, thanks!