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.
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!
Understanding Python through its builtins
21–30 of 180 posts
Re: Understanding Python through its builtins
#22Are 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
#23Earlier quoted context omitted.
Huh I never even thought we would need to create copy of an object when adding new item to it (like a new item to list for example). Is there any drawback on doing that in standard pythonic way? I actually learned to program using Python and it was my first language. Since then I only used JS. In both I like using functions a lot and rarely dabble in OOP since it is more conveniet to me.
You often lose performance in traditional imperative languages when aiming for persistence. When you have immutability guarantees (like in many functional programming languages like ML or Haskell) you can avoid making copies by sharing the parts of the data structure that don't change. If this kind of thing interests you, you should check out Chris Okasaki's book "Purely Functional Data Structures".
But immutability sure is nice when you can have it.
Re: Understanding Python through its builtins
#24I can appreciate this must have taken considerable effort, It reads really well. Thank you!
Re: Understanding Python through its builtins
#25Are 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.
That said, I think I had good luck with Writing Idiomatic Python.
Re: Understanding Python through its builtins
#26Earlier quoted context omitted.
>Python is really consistent when it comes to its behaviour True, though you end up with things like: ' '.join(thelist) Instead of thelist.join(' ') Because of the somewhat aggressive mantra to be consistent.
But that's good. Because a string just needs to know aboit interable to perform that operation whereas every iterable would need to implement it's own join if you had it the other way around.
Re: Understanding Python through its builtins
#27This is such a good write up for someone like myself still trying to get their head around Python. I can appreciate this must have taken considerable effort, It reads really well. Thank you!
Re: Understanding Python through its builtins
#28I once tried to catalogue all the stdlib operations which release the GIL, meaning if you use only those (well, only those "heavy" bits, you can still use other small blocking glue bits), you can do "real" multithreading.
It was a fun exercise!
Re: Understanding Python through its builtins
#29Are 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.
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
#30In addition to this, I highly recommend just reading the codebase. I haven't written C since college and it's remarkably readable. I once tried to catalogue all the stdlib operations which release the GIL, meaning if you use only those (well, only those "heavy" bits, you can still use other small blocking glue bits), you can do "real" multithreading. It was a fun exercise!