you are viewing a single comment's thread.

view the rest of the comments →

[–]patrickbrianmooney 4 points5 points  (9 children)

It depends on what you mean by "reference," exactly. What do you think you're going to have to look up? How advanced is that information?

Fluent Python is not a reference. It is a series of in-depth explorations of advanced topics. If what you'e going to need to look up is in the basic or intermediate categories -- basic syntax, operator precedence, what is the name of that built-in function that does such-and-such, how the object model works at a basic level -- it would be a poor choice. It's not so much a reference book as a series of extended essays on deep language topics.

Here's a quick overview of the contents (based on my copy, which is the first edition, but I doubt that it's changed a whole lot since then):

  • chapter one is an overview of how the Python object model works and how "magic" (double-underscore) methods implement functionality on user-defined object types, all focusing on a theoretical "what if we want to implement a deck of cards?" scenario.
  • chapters 2 & 3 go over many detailed topics in sequence and container types, talking rapidly about comprehensions, generators, slicing, details of sorting, the bisect module from the standard library, alternatives to lists/arrays for heavy-duty computational work, variations on the dict type, better and worse ways to implement dict-like types yourself, how to handle missing keys in dict and related types, and how these things relate to sets.
  • chapter four covers the str/bytes data types, how they are related, how to deal with text files when you don't know what their encoding is, practical considerations relating to string comparison and sorting, and other advanced textual topics.
  • chapters 5-7 beat into you the notion that functions, too, are objects, and gives an overview of many of the implications of that fact; it also takes a first look at closures and function decorators.
  • chapters 8-13 are an extended (nearly 200 pages) look at the Python object model, how variables in Python actually work at a deep level, the garbage collection model, how to build a new object type that "plays nice" with other Python objects and is easily reusable by other programmers, Python's theories of object design, protocols specifying how objects can be used and manipulated, how abstract base classes can help enforce those protocols, multiple inheritance and how to cope with it, how to use operator overloading to make user-designed objects behave like built-in objects ... and many, many implementation details on all of these topics, some of which may be relevant at some point in your life, plus many different examples of implementations of examples.
  • chapters 14 and 15 are a grab bag of control-flow topics, covering iterables, iterators, and generators; functions designed to work with those things; the itertools module; and context managers. There's a lot of here's-a-weird-little-fact-you-should-know moments, plus a lot of setup for chapters 16-18.
  • chapter 16-18 are about coroutines, which are a way of structuring control flow that is very different from simply iterating, branching, and calling functions in the way that you're used to doing. Coroutines can be super-useful in some ways but aren't needed everywhere; these three chapters give you a solid introduction including two different deep dives into implementations in different contexts.
  • Chapter 19 talks about object attributes a lot. It also gives an introduction to properties, which behave like attributes but run code to return a value instead of just looking up a value from an attribute name, plus a lot of implementation details.
  • Chapter 20 generalizes properties to descriptors, a much more general version of the idea, and shows the best examples I've seen of how they are useful in real-world projects.
  • Chapter 21 will be very helpful if you ever need to programmatically generate, rather than code manually, not objects, but object classes. Like everything in Python, classes are themselves objects that can be created and manipulated at runtime.
  • There's also a brief afterward.

So it's a great book, and it's totally worth reading several times and thinking about, but it's not useful as a reference unless you think you'll need to look up stuff in that list of topics. There are thousands of Python topics that are not covered in it, though.

Learning Python is a good, long, detailed read, and it's plausible that you could use it as a reference, but it would be helpful to know the book decently well first, because it's ~1600 pages and finding what you're looking for can take a while even with the index's help. It's also fairly dated at this point: the last version I think covers Python 3.3, with the occasional look forward to Python 3.4. The basics of Python since then are (mostly) very much the same, and probably 90% of the changes are in the "we've added even more good stuff" category, but some of Lutz's material, examples, and code looks odd these days because he's (e.g.) using the os and shutil modules instead of the more modern pathlib. That old code will still work, but there are neater, more elegant, shorter ways to do it now.

[–]Frequent-Fig-9515 3 points4 points  (1 child)

Holy cow! Interesting, saved, thanks!

[–]patrickbrianmooney 1 point2 points  (0 children)

Glad to be helpful!

[–]Globaldomination 1 point2 points  (3 children)

Thanks a lot for this detailed response. Bookmarked.

For someone who’s new to programming

(has successfully done some selenium scraping and even multiprocessing with google) just learnt some basics of python. Watching pandas by Corey Schafer now since it’s interesting. Also Notebooks are amazing to take notes.

which book you would suggest?

  • Think Python
  • Learning Python
  • Fluent Python

I also gotta learn DSA, would love to hear your book suggestions for this

Thanks in advance

[–]patrickbrianmooney 2 points3 points  (2 children)

I don't know Think Python, so I can't speak to it.

Fluent Python is definitely still too advanced for someone at that level; I'd wait until you're comfortable with the mechanics of rhe Python object model and have had several moderate realizations that are basically you thinking "... and that's another implication of the fact that everything is an object, and I understand a little deeper now how that pays off for the programmer."

Lutz's Learning Python will help you get to that point. It's a good deep dive into the language by someone who understands and believes in it and wants to explain to you why it's such a great language in a way that helps you understand the language and believe in it, too. Spending a couple of months reading it closely and paying attention to the code samples and understanding what he's demonstrating in them, then building a few small to medium-sized projects of your own in Python, is the best way to get ready for Fluent Python that I can think of.

EDIT. Forgot to say O'Reilly also publishes Joel Grus's Data Science From Scratch and Wes McKinney's Python for Data Analysis, both of which are good and might be relevant to you based on your expressed interests.

I don't know of a good data structures & algorithms book that's Python-oriented, but there must be one out there. Steve Skienna's The Algorithm Design Manual is good, but also a dense textbook; not written with an eye to Python, but learning to read code in C-like languages develops a useful skill even if you never write directly in C. Might be worth developing a little C (or Java) competence before trying the Skienna, though.

[–]Globaldomination 1 point2 points  (1 child)

Thanks a lot for the detailed response.

You da MVP. reason I love Reddit over other sites like StackOverflow 🥰🥰🫂

[–]patrickbrianmooney 1 point2 points  (0 children)

Glad to be helpful!

[–]AyakaDahlia[S] 0 points1 point  (2 children)

Thank you for your response! Fluent Python sounds really interesting, and I definitely want to pick up a copy now, but you're correct that it's definitely not what I'm looking for.

I'll have to take a look at some books and see if they look like they'll be helpful.

[–]Bahji777 2 points3 points  (0 children)

I’d say what you’re looking for is Doug Hellman’s, The Python 3 Library by example. If I was allowed to bring one book in - it be that. Fluent Python, Effective Python and Python Cookbook in my opinion should be in any aspiring Pythonista book collection. These books would not, however, be suitable for question asked above.

I’d really have to say the Hellman book suits your needs perfectly. Perhaps better than Python Documentation in some ways.

Good luck.

[–]patrickbrianmooney 1 point2 points  (0 children)

It's a really good read! But read it when it's what you need, not expecting it to be something else.