I am in intermediate level Python dev (mainly work with Django) but looking to level up. I learn by doing so any recommendations for hands on material to help learn more?
The best way to improve is by writing more code in python. You can develop a desktop gui app or an open source python package to challenge your python skills.
Python from the start is a “higher performance” hack of a language (wrap everything you do on a try block because the language is so finicky and inconsistent failure is the most reliable way to know something is false.)
Find a good example and follow it while writing more code.
unless you're arguing for checked exceptions I don't see the evidence for inconsistency. Plus when it comes to knowing when something "is False" python's far more strict than c++'s boolean conversion rules.
"just write more code" is terrible advice and I'm not sure why I see it so much, that's how you end up with 1 year of experience 10 times vs 10 years of experience.
it would be like practicing a sport and just making the same mistakes without changing form or strategy
This is the best way to pick up the fundamentals of a language, but definitely not appropriate for learning deeper concepts. You can only learn what's new. If you're driving yourself, "new" can only be stumbled upon, which is extremely inefficient. It's much better to find somewhere with a consistent presentation of "new", like a book, or complex source, written by people that regularly use the "new".
What do you want to achieve by learning advanced Python?
What does advanced Python mean to you?
Answers will dictate what makes sense for you. Since you said you're a Django dev, maybe try re-implementing a library/dependency you use. Start with something obvious, and then maybe something less so.
You'll learn quickly how much of it is advanced Python vs advanced Django. Python is very deep, but you don't really need to know most of it. And the ones who do, know it because they were trying to accomplish something specific.[1]
OP here. Thanks for replying. Most of my Django code is dead simple - validation, business logic, crud operations. Loops, conditionals, the occasional string manipulation, dicts, sets and exception handling. Very rarely a list comp.
Almost never dunder methods, writing an annotation, oop, generators, worrying about concurrency, threads, locks, etc. Things that I know the equivalent of in Java very well since I came from that world.
The list of things you never use reads just like the table of contents of the book.
I've only read 1st edition but I imagine the 2nd edition is more relevant now.
I have this same question and also work in Django, so I think I know what OP is asking about.
Django's code leans heavily into advanced Python features like metaprogramming. To use Django, you don't need to understand it, but once you start customizing things or building on what Django provides, you need to read through Django's code to understand it. And if you don't know things like metaprogramming, you'll get lost quickly.
There's not a lot of great resources for intermediate Python developers to learn these concepts. I tried reading Fluent Python but found it difficult to follow. I then checked out Learning Python 5th Ed., which is a little dated at this point, but has some good chapters on metaprogramming at the end.
That's basically how I started to get my arms around these advanced Python features to be able to understand Django's codebase a little better.
I am working through Fluent Python as well but it's a long slog. Most of my Django code is dead simple from a Python perspective (altho quite complicated use of the ORM, etc).
There is two different things here, “advanced” Python that applies to webdev, and other areas of Python (data science, ML). Three things I would recommend:
1. As a Django dev dig deep into Django’s internals, there is loads to learn from its codebase, particularly meta classes in the orm and form frameworks. The template engine is also highly complex. Try building a tool that scratches your own itch with Django, and integrate it deeply using some of the techniques Django uses. Read lots of its code, work out how it works.
2. I think a good project to explore other areas of Python would be a web scraping then data processing project. Find something that interest you, build a scraper that extracts LOADS of data from the web or a specific site about it. Then analyse that data using NumPy and Pandas. It will teach you a bunch of new tools.
3. If you are interested in ML there a loads of interesting academic projects that have released their code on GitHub. Find one that, again, interests you (image processing, text generation, computer vision), download it, get it running, and then modify it to do something else. Or package it as a web app or something. You will learn loads about how these tools work.
If you're interested in web dev take a look at FastAPI. In many respects it's a better Flask and leverages schemas for your requests and responses (Pydantic models), async processing and dependency injection. I wouldn't call it advanced but it incorporates features of what some refer to as "modern" Python. As someone who's been using Python for coming up 20 years I learned a lot.
I'm going to echo what someone else mentioned and suggest diving into the Django source. I think it's a really well done, well organized code base. They are always in need of contributors for various issues, maybe you could investigate a bug or two. Anyway, this is what was recommended to me when I wanted to "level up" my Python experience, and I think I learned a lot by doing it.
In addition to reading about Django, since that's what you use, I'd suggest finding a small bug to fix in the core project or a still-developing project in the ecosystem. It's a pretty mature project, so there's not a ton of low hanging fruit, but with new releases (like 4.1 that just dropped), there's always a few weird edge cases to fix.
Claim the issue and ask for some help (after doing your homework), and I suspect you'll get helpful direction. That was my experience anyways.
It will likely take some time to find something that looks interesting and solvable, but that's the best way to learn IMO so it's worth the grunt work.
Literature if you want to get better at using the language and gain a deeper understanding of it: "Effective Python" and "Serious Python". Also have a look at the Python standard library documentation and e.g. the data model documentation, plus the release notes of recent Python versions (e.g. pattern matching). Tons of interesting material there.
Hands-on stuff: Write command-line tools and libraries that are useful for yourself or that are somehow fun. Try out some existing or 3rd party libraries.
No I haven't, but if I wanted to improve my coding skills (which I'd rate as intermediate) I would do one of their projects. My company would pay for it, but that's not a concern ($80/mo is nothing to me). Main investment is time, as you said, but it's probably worth it. I'm just too lazy/busy to do this right now.
* "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
I'll second Serious Python. It's a fairly quick read, and introduces a number of topics concisely. It helped me become more aware of areas of Python that I'd like to learn more about.
I have other higher-level Python books that I'm taking much longer to get through because they're more in depth. Serious Python strikes a really nice balance of covering things well enough to help you understand them, but not going into so much depth that you take forever to get through the book.
I want to second all the opinions about fluent python, serious python and practices of python pro. I probably own most python books out there, and if I had to recommend one, it would by fluent python 2nd. The 2nd edition has a lot of type checking stuff that's really cool.
Two more resources that I really like:
1. Pycon videos - they're posted free on youtube. It's a great way to explore interesting problems with interesting people.
2. Another book on python by Harry Percival (he does a lot of TDD stuff) - Architecture Patterns with Python. This book is relatively new. It targets an rather niche audience (web devs). But it's hard-won knowledge and really well written. It's a wonderful resource for python devs, and a book I wish more people knew about. https://www.oreilly.com/library/view/architecture-patterns-w...
I think “Architecture Patterns with Python” is a great book on multiple levels. First off it shows the natural progression of you code base as you build out features, achieve higher performance or want to increase reliability. Secondly it nicely puts the theory in to practice. Which perfectly lives up to “Although practicality beats purity” in the Zen of Python.
Thanks! I'll have to check out "Clean Code in Python”. Packt books seem to have more quality variance in my experience, but perhaps this is one of the good ones.
Glad that this is on Oreilly so I can read a few chapters first.
I know very little about Python, but I would suggest these talks about a few ways in which Python is unique. They won't teach you Python, but they might help in making sense of the confusing bits you might encounter:
31 comments
[ 5.9 ms ] story [ 86.7 ms ] threadYou will need good examples.
Python from the start is a “higher performance” hack of a language (wrap everything you do on a try block because the language is so finicky and inconsistent failure is the most reliable way to know something is false.)
Find a good example and follow it while writing more code.
it would be like practicing a sport and just making the same mistakes without changing form or strategy
What does advanced Python mean to you?
Answers will dictate what makes sense for you. Since you said you're a Django dev, maybe try re-implementing a library/dependency you use. Start with something obvious, and then maybe something less so.
You'll learn quickly how much of it is advanced Python vs advanced Django. Python is very deep, but you don't really need to know most of it. And the ones who do, know it because they were trying to accomplish something specific.[1]
[1] Tweet about slots by author of Flask - https://mobile.twitter.com/mitsuhiko/status/5004329133817487...
Almost never dunder methods, writing an annotation, oop, generators, worrying about concurrency, threads, locks, etc. Things that I know the equivalent of in Java very well since I came from that world.
The list of things you never use reads just like the table of contents of the book. I've only read 1st edition but I imagine the 2nd edition is more relevant now.
Django's code leans heavily into advanced Python features like metaprogramming. To use Django, you don't need to understand it, but once you start customizing things or building on what Django provides, you need to read through Django's code to understand it. And if you don't know things like metaprogramming, you'll get lost quickly.
There's not a lot of great resources for intermediate Python developers to learn these concepts. I tried reading Fluent Python but found it difficult to follow. I then checked out Learning Python 5th Ed., which is a little dated at this point, but has some good chapters on metaprogramming at the end.
That's basically how I started to get my arms around these advanced Python features to be able to understand Django's codebase a little better.
1. As a Django dev dig deep into Django’s internals, there is loads to learn from its codebase, particularly meta classes in the orm and form frameworks. The template engine is also highly complex. Try building a tool that scratches your own itch with Django, and integrate it deeply using some of the techniques Django uses. Read lots of its code, work out how it works.
2. I think a good project to explore other areas of Python would be a web scraping then data processing project. Find something that interest you, build a scraper that extracts LOADS of data from the web or a specific site about it. Then analyse that data using NumPy and Pandas. It will teach you a bunch of new tools.
3. If you are interested in ML there a loads of interesting academic projects that have released their code on GitHub. Find one that, again, interests you (image processing, text generation, computer vision), download it, get it running, and then modify it to do something else. Or package it as a web app or something. You will learn loads about how these tools work.
But in general, I agree with you that FastAPI introduces a lot of concept that are very useful to learn.
Claim the issue and ask for some help (after doing your homework), and I suspect you'll get helpful direction. That was my experience anyways.
It will likely take some time to find something that looks interesting and solvable, but that's the best way to learn IMO so it's worth the grunt work.
Hands-on stuff: Write command-line tools and libraries that are useful for yourself or that are somehow fun. Try out some existing or 3rd party libraries.
It was discussed yesterday: https://news.ycombinator.com/item?id=32342334
* "Fluent Python" (https://www.oreilly.com/library/view/fluent-python-2nd/97814...) — takes you through Python’s core language features and libraries, and shows you how to make your code shorter, faster, and more readable at the same time
* "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
I have other higher-level Python books that I'm taking much longer to get through because they're more in depth. Serious Python strikes a really nice balance of covering things well enough to help you understand them, but not going into so much depth that you take forever to get through the book.
Two more resources that I really like:
1. Pycon videos - they're posted free on youtube. It's a great way to explore interesting problems with interesting people.
2. Another book on python by Harry Percival (he does a lot of TDD stuff) - Architecture Patterns with Python. This book is relatively new. It targets an rather niche audience (web devs). But it's hard-won knowledge and really well written. It's a wonderful resource for python devs, and a book I wish more people knew about. https://www.oreilly.com/library/view/architecture-patterns-w...
A second book I think nicely compliments this book is “Clean Code in Python” by Mariano Anaya (https://www.packtpub.com/product/clean-code-in-python/978178...). To really perfect the implementation of the architecture in the first book.
Making beautiful code starts by making every line count. Then by making all lines add up.
Glad that this is on Oreilly so I can read a few chapters first.
How Python was Shaped by leaky Internals, Armin Ronacher: https://youtu.be/qCGofLIzX6g
What Does It Take To Be An Expert At Python?: https://youtu.be/7lmCu8wz8ro
and maybe also
When Python Practices Go Wrong: https://youtu.be/ZdVgwhHXMpE