Think Python, 3rd Edition
allendowney.github.io
allendowney.github.io
Now it's actually happening. :D Even better, he's taken it further by adding cool tools such as a Jupyter-based turtle that shows inline graphics in the notebooks. I strongly suspect this will turn out to be the best way to learn Python programming when it's released.
Oh and I just remembered, we even showed a proof-of-concept of converting some of the 2nd edition of this book into nbdev notebooks: https://github.com/fastai/nbdev_cards/blob/master/01_deck.ip... . That notebook is rendered as this HTML: https://fastai.github.io/nbdev_cards/deck.html
I loved Think Bayes and Think Stats, but it felt a bit off when everyone else were using notebooks.
When I learn a new language with e.g. AdventOfCode, my first task is building a jupyter image for it.
(I came across Think Python when I was trying to help other people learn how to program. So I did not learn programming from Think Python, and Python is also not my favourite language. (It's also not my least favourite language, either. Far from it.))
It's not just a book about a language, but an introduction into the basics of solving problems as a programmer.
I am considering changing the trajectory of my own life, towards a more community/maker/teacher role, and I have a freelance/small business idea about teaching but I need sort of "soft syllabus" materials.
I am learning Python myself, having just never had a need for it in all of my professional web development life (I've written apps in just about every other web-focussed programming language, including Perl and Ruby).
It looks like the right language to teach general concepts in, and having a book I can draw from will help.
But I am, well, mid-life at best, and the only crisis I am experiencing is that I think much of what I have done for years is worth less than I would have hoped.
I think it is ironic that technology seems to serve people less and less (and advertisers more and more) at just exactly the same time as every possible piece of technology is falling in price and increasing in availability.
Want to make a small device with a colour LCD display, buttons, an entirely custom enclosure, a rechargeable battery and a custom PCB? The cost of doing that has never been lower. Even if you only want one.
Want to give some tool a comfortable handgrip for accessibility reasons that needs to be parametrically adjustable? The software tools are free and the prototyping tools are incredibly cheap.
Want to find the answer to a question about your local area that would have required months of library time? The software is free and shockingly complete data sets are available from governments.
So why do so many people, even adults my age and younger, feel that technology is out of their control?
I have always felt as a freelance developer that the work I am paid for is just the seed in the middle of a larger fruit, where I listen and discuss and explain and educate.
I feel I should be turning it inside out. Making the listening, discussion, education the product, and the development work ancilliary to it (because it almost always is).
What I find interesting about Python, specifically, is how many applications it is suitable for, considering its ease of access -- CAD packages, 3D printing, PCB design, GIS, microcontrollers, statistics. Children's and adult education etc.
So while I have a little time I am spending it re-orienting myself into Python as a programmer "way-of-life", and away from the tools I have been using so far (which has never, really, meant Python).
And as I do so I am getting a sense of how it might fit into me turning my freelance work inside out to become a teacher/trainer/educator/facilitator, largely for adults, to help them have better concepts of technology (even for just the humdrum business of getting suppliers to quote for bespoke projects).
A vague sketch, sorry -- but I think this might answer your question.
I do admit that I haven't had the first-hand experience of optional typing in Python supported by something like PyCharm so it is possible that the tooling has brought the experience to be comparable to working with a statically typed language. If someone has used IntelliJ community edition with Python typing-enforcement turned-on, please share your experience.
There's a lot of context and drudgery involved in programming that can dissuade people before they get to that magical moment, and they can blame themselves and think they weren't smart enough because they don't understand that the deck was stacked against them. For instance with Python, broken virtual environments can be really dissuading for new programmers.
I think Java's opinionated and verbose nature can be cumbersome to beginners, who have never debugged a type confusion issue and so don't give a hoot about static typing. But I think after programming in Python for a while, they'll see why eg declaring what exceptions you'll raise is tremendously helpful.
(I was sharing a table at a conference with Allen some time ago and told him how many times I'd recommended or bought people his books, and I think he thought I was bullshitting him.)
Also just reading Norvig’s annual Advent of Code implementations usually provides some insight on how to write elegant and concise Python code.
https://docs.python.org/3/tutorial/index.html
https://docs.python.org/3/library/index.html
Whenever a new version is released, I read its What's New documentation.
Beyond that, I like to read source code, both for the stdlib and popular third-party packages. This advice generally applies when I'm learning any new language or re-familiarizing myself with one, not just Python.
Python official docs are not completely horrible, but compared to most other popular languages (Kotlin, Scala, Rust, Go at least), the Python official docs are kind of meh.
I suppose Python docs beat C and C++ which do not have official docs besides the spec. (not counting K&R and Bjarne's books).
Also I guess Javascript does not have official docs (ie MDN is not official)
* Serious Python (https://nostarch.com/seriouspython) — deployment, scalability, testing, and more
* Practices of the Python Pro (https://www.manning.com/books/practices-of-the-python-pro) — learn to design professional-level, clean, easily maintainable software at scale, includes examples for software development best practices
* Intuitive Python (https://pragprog.com/titles/dmpython/intuitive-python/) — productive development for projects that last
* Advanced Python Mastery (https://github.com/dabeaz-course/python-mastery) — exercise-driven course on Advanced Python Programming that was battle-tested several hundred times on the corporate-training circuit for more than a decade
I know only Fluent Python which I'm currently reading, and CPython Internals.
At a certain point of expertise, everything after basic journeyman familiarity, there's nothing left but to read code and write code.
https://www.redblobgames.com/ has lots of really nifty articles, too.
For example, Effective Pandas 2 illustrates common patterns for dealing with tabular data. Along the way, it uses comprehensions, lambdas, unpacking, etc. Shows how to use pytest to refactor. Leverage visualization to understand data.
(Disclaimer: I'm the author)
It's a little known book that explores different ways of solving the same problem under different constraints.
Think Python 2e - https://news.ycombinator.com/item?id=35421096 - April 2023 (30 comments)
Think Python: How to Think Like a Computer Scientist - https://news.ycombinator.com/item?id=1586000 - Aug 2010 (9 comments)
Will definitely keep my eye on this.
Also neat:
> What happened next is the cool part. Jeff Elkner, a high school teacher in Virginia, adopted my book [Think Java] and translated it into Python. He sent me a copy of his translation, and I had the unusual experience of learning Python by reading my own book.
I highly recommend the intro to Functional Programming in Raku (chapter 14). https://greenteapress.com/wp/think-perl-6/
For various reasons, I did not finish that: but what did got written, wound up as a 24-part blog series on dev.to: https://dev.to/lizmat/series/24075
There's Ray, Pyro, Pykka, Celery, multiprocessing, asyncio, threads, Qt, and more, but all of them have issues. And a lot of it boils down to the GIL, although "processes" that are doing I/O such as TCP and other network communication should ideally reduce the GIL effect, to my understanding (is that right?).
From what I can tell, it's basically one of the worst language choices for systems of this nature, but I am trying to figure out how to do it because I need to.
It definitely isn't, but this is a new role with a rushed timeline in a place dominated by Python.
> and it works but I find the code extremely hard to reason about
This is also a major concern of mine.
It may feel limiting but my advice would be to keep all the celery job queue stuff isolated from your server, especially if you are using an async web framework. Have your web server just put all the jobs in the celery queue and let it handle executing them, regardless of whether they’re cpu or io-bound. If you try to optimize too much by doing something like leaning on celery for cpu-bound tasks but letting your web server handle the io-bound ones you’re going to be in for a world of hurt when it comes to both debugging and enforcing the order of execution. Celery has its warts but you’ll at least know where in the system your problem is and have reasonably good control over the pipeline.
What about using Pkykka alongside Pyro such that each Pyro remote object is actually a Pykka actor? Such that Pyro allows splitting workers across separate Python OS processes and the "messaging" while Pykka handles the internal state.
In Python, it could be a class managing a session type of object, like a TCP socket connection, or managing some piece of hardware that is doing something independently of the other parts of the system, or a database writer, etc.
"I have to work in a language other than Erlang/Elixir and I don't like it"
But Erlang/Elixir are defined by the sort of concurrency model that you say you want, so as far as I can see your question would be just the same if you were asking about Java or Go.
If you have a question like "I can do this in Java or Go. How do I do it in Python?" Then people might be able to help. But please stop with the criticism of Python for not being Erlang/Elixir, since Java and Go also are not that.
This is honestly pretty frustrating trying to build a system like this in Python. If you think asyncio, coroutines, tasks, multiprocessing, threads, subprocesses, etc. are simple and understandable in Python, then I would love for someone to explain them to me in a way that is manageable.
And no, the question would not be the same. Java and Go have proper concurrency substrates. Python does not.
Inside that coroutine get the loop and await loop.sock_accept(sock)
And then asyncio.create_task(on_connection_data(connection)).
The only gotcha is you need to keep a reference to that task so it doesn't get garbage collected.
Consider organizing the code using TaskGroup.
"The default build implementation is a generational collector. The free-threaded build is non-generational; each collection scans the entire heap."
https://devguide.python.org/internals/garbage-collector/
https://docs.python.org/3/library/gc.html
(And as someone else pointed out, asyncio's event loop keeps only weak references to tasks, so the GC implementation doesn't really matter here.)
My understanding is that multiprocessing creates multiple interpreters but that it still comes across some GIL issues if all under the same Python process.
I am in general quite comfortable with the actor model, and I would ideally use Erlang/Elixir here, but I can't for various reasons.
I saw that at one company having RabbitMQ / Celery setup - every time a new software engineer comes in, they complain about RabbitMQ and ask why would company use it. The infrastructure was running like this without hiccups for years. At one point company has let go of many experienced engineers and this time one developer found some issue with the code and blamed it on rabbit as it was locking the queue. There were no more senior developers to contest it, so he convinced manager to swap it out for Redis. He took about two months to rewrite it. Surprise, the same issue existed on Redis. The Redis solution works fine, but has its own limitations...
This is a comprehensive resource that I use as a reference. Happy reading!
Typescript might be nice because of how it’s a gradual typing system, just try and do a bit more and more with it as you go.
"Python Type Challenges" (https://github.com/laike9m/Python-Type-Challenges) — Master Python typing (type hints) with interactive online exercises
A bit more advanced, and geared towards library authors, is Type-level Typescript.[1]
[0]: https://github.com/total-typescript/total-typescript-book
Examples in typescript (so syntax should be familiar compared to e.g OCaml) and teaches you how to model a domain in types and how to think in terms of a type system, instead of diving into the details of how to implement one.
If you want to understand type systems, Types and Programming Languages (https://www.cis.upenn.edu/~bcpierce/tapl/) is the book most people start with. If that is too advanced for you, PLAI (https://www.plai.org/) is a gentle introduction to programming language theory which includes type systems.
(By 'reasonably typed' I mean something like Haskell, OCaml, even TypeScript or Facebook's hack. But not Go, C++ or Java.)
So now I wonder, do people really spend so much time in weakly typed languages that types seems to be a special concept? Or is there something about types that has gotten so complex that its worthy of extra study?
*I did do some BASIC as a middle schooler but it didn't stick. C did.
https://www.manning.com/books/type-driven-development-with-i...
https://www.whsmith.co.uk/products/think-python-how-to-think...
https://blackwells.co.uk/bookshop/product/Think-Python-by-Al...
(Blackwells think September, incidentally, whereas WHS think the end of July)
Amazon just list books way, way earlier in pre-order than a lot of places.
Now I've come a long way to become an actual developer shipping real products and have certainly learned a whole lot more on the topic, but I still think the first steps are the most important/difficult ones. Although I've moved away from Python towards other platforms such as Rust, the basic concepts covered in this book are still very much relevant.
I'm really excited to learn that Think Python has become more modern and interactive with this update!
If you already know everything in the tutorial, then try a project in Python that you did previously (familiar project, new language—Python).
Glad to see it evolving!
in the meanwhile, how has your personal experience been around this? what worked for you, especially when you use a third-party notebook solution where you may not be able to install jupyterlab extensions?
Why would anyone bother with learning anymore? When is learning enough to get started?
How will someone get started with work? What qualifies someone to start a new position?
Pretty sure only smart people will be hired for the roles.
No matter what I do, I am forever unqualified, even from junior roles.
1. Have post grad degree
2. Have internships
3. Have only part time or short tenure roles.
But can't get into any industrial role. Why?
Means, I die? What qualifies for a job?
Well one option is to go back to shithole country I came from and just stay there earning pennies. With the money I make there affording a new mac will take 2 years salary. So that is the kind of shithole I am talking about.
Seriously, why?
Everywhere I've ever worked in tech, in my 20 year career, has had people from all backgrounds.