200 Bulletproof Python Tips That Will Instantly Make You A Better DeveloperPythonista, how many Python tricks do you have up your sleeve?
Are you tired of reading through long tutorials where you’ve lost interest by the time you get to the actual code or meat of the subject?
Are you so overwhelmed by the richness of the Python language that you’re finding it difficult to learn the many different branches?
Do you wonder how you can make your code more elegant, maintainable and Pythonic?
This was certainly us when we started our Python journeys!
One of Python’s strengths is that while it’s so deep and technical it’s also a wonderful entry level programming language. This contrast though can be paralyzing for folks that want to go from doing things the “basic way” to doing things the Python way.
There is an answer however and we have a solution that will once and for all make things more accessible for you. Read on to hear more... or just buy the book! We don’t mind either way!
Enter PyBites Python Tips.
This book contains small, practical pieces of Python code that will boost your knowledge of the language.
We quickly realised that the sooner you start reading and applying code, the quicker you progress.
As a result we’ve distilled almost 4 years of PyBites into a rich collection of tips that are insightful, practical, fun and presented in such a way that you can get straight to coding with them.
You’ve probably seen some of these on social media in the last couple of years. They’ve helped thousands of developers worldwide improve their Python skills so we know they’re good.
These tips have reminded developers of Pythonic ways of doing things and why Python is such a great language to code in.
Let’s take a quick tour.
Firstly, you can consume the book in any order. Just pick out the topics you want to learn about or need the most at any given time.
We’re always trying to battle the widespread tutorial paralysis we commonly see in the industry. That is NOT the experience we want you to have with us.
Head over to page 18 and you will learn how to construct a dictionary from 2 iterables (one of our favorite idioms).
Powerful sorting options
On page 23 you will discover how to sort any sequence by a callable you define. Your sorting skills will never be the same again (when Julian dreams about Pythonic code, you bet beautiful sorting is part of it).
On page 30 you will learn about an exciting module to do sentiment analysis on a bunch of tweets.
Yes, these tips go far beyond Python’s standard library. You’ll even learn some Django.
Builtins you want to know about
We are showing you a lot of built-ins that will make your life easier and your code more idiomatic.
Head over to page 34 to learn about two elegant one-liners thanks to any and all.
On page 40 we show you some invaluable ways to inspect objects in Python, an unmissable skill for any Python developer.
Starting page 44 you will find two recipes to make an infinite iterator followed by how to get all combinations from a list.
This module is so awesome! It helps you combine sequences of different length (page 152), chain iterables (page 160), even slice a generator (page 164). The itertools module occurs in no less than 11 tips!
What’s up with __main__?
We also care about the newer Pythonistas.
If you’ve wondered what if __name__ == “__main__” is about, we’ve got you covered on page 61.
A lot of folks we talk with see OOP as THE magic they need to know to become proficient at Python. And they are partly right.
We have several tips that cover this. On page 53 you’ll see that everything is an object in Python (this haunts Bob’s dreams at times, in a good way).
On pages 65 and 103 we talk about object representation and how it helps debugging.
OOP is really everywhere in the language and on page 70 you see a different dict constructor at work.
Or what about powerful Path (pathlib) methods which you’ll see on page 73?
On page 87 you’ll learn about the callable and getattr built-ins, and similarly on 102 you will learn about attrgetter from the operator module.
You will live and breathe properties with tips 101 and 139!
Finally, do a search on “class” and you will see quite a few of them.
We hope this covers enough OOP for starters ;)
We go beyond Python by showing you some powerful tools.
Head over to page 74 to use json.tool to validate JSON.
On page 75 we create a gif image using the imageio library.
Then on page 82 you’ll learn about the cool howdoi tool to search for code snippets using the command line.
And on page 113 you will learn about Django extensions.
How __all__ can save you
We also think about people writing modules for other developers’ consumption.
On page 92 you will learn about a technique to encapsulate your code so that even somebody doing an import * won’t see all your stuff ...
Robust testing techniques
We are keen on writing test code so expect to find pytest / testing related tips as well:
- On page 96 you will learn how to make your test code more DRY (don’t repeat yourself)
- On page 97 you learn how to mock out web services in your tests (similarly on page 51 you will learn how to cache API calls).
- On page 104 you will learn about the assert_called_with method.
- On page 105 you will learn how to access an exception string caught by pytest.raises.
- On page 110 you will learn about how to test datetimes.
- On page 145 you will learn about pytest's killer feature: fixtures.
- And on page 155 you will learn how to tactically skip a test based on a condition.
Powerful data structures
Have you heard about the collections module?
If not, time to get to know it! There are 8 tips dedicated to this awesome module.
On page 29 (and 160) we'll meet the awe inspiring Counter container, on page 101 we show you when to use a deque over a list. Page 142 shows some of its wrappers to make your own data types. On page 158 you'll learn about namedtuples. And last but not least tips 80 and 147 are dedicated to defaultdicts.
Useful datetime methods
On page 57 we look at the calendar module which made it relatively easy to build our (Seinfeld) coding streak calendar on our platform.
You will learn about fuzzy parsing using the powerful dateutil library on page 100.
And you will learn about what day of the week, and what week of the year it is on pages 114 and 115.
We use the powerful timedelta in tips 101 and 108. There are no less than 10 tips where we use datetime!
Speed up downloads
On pages 138-140 we'll introduce you to concurrent.futures speeding up web downloads tremendously. We'll use the timeit module to measure performance. And we round things off introducing you to a tool to make a beautiful progress bar.
Python 3.9 coverage
On pages 129-133 we got 4 tips dedicated to new Python 3.9 features. No more excuses: use the latest and greatest version of Python (as of the time of this writing)!
Well rounded Pythonistas know their generators :) - no worries, we got your back here too! On page 123 we share a date generator we still use today to create WINS files. And on page 163 you will learn about "yield from" for even more concise generators.
The Standard Library inside out!
After hitting the low hanging fruit, we go deeper and discover lesser known (or used) modules like shlex, getpass, uuid, zipfile and operator. You will learn Python inside out!
We hope you’ll agree by now that there is a lot to learn.
We’re actually positively surprised we were able to fit this into just 225 pages!
And as our tips are so practical, we cannot wait to see you putting all of this into your own code.
This brings us to the exercising part.
Where relevant we have linked exercises you can take on our coding platform.
Remember: retention increases 3-5 fold when you put what you learn into practice.
We even recommend you teach what you learn here to benefit from a 10X retention rate.
How our community experiences our tips
Our tips are widely acclaimed by the Python community as being revealing, helpful, insightful, Pythonic, practical (they can be implemented immediately in one’s code base), and fun.
"This is truly a vital addition to every Python programmers toolkit: bang up to date with tips that work correctly on the latest versions of Python. Each tip has appropriate references to online documentation if ever further elaboration is needed. Get out the shredder, you're not going to be short of kitty litter for some time after you rid yourself of all those old dated Python 2.7 hints and tips books: PyBites Python Tips is the premier collection of tips for today's Python. Buy it now: buy it twice and do a friend a favour!" - Geoff R
"In terms of knowledge per dollar this is the best investment I've made in the past few years. This is honestly my favorite technical book. Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that. Each tip is one page: there's some code, an explanation and links to resources if you want to read more. It's not only all you need, it's all you want. I wish there were more books like this!" - Sergio S
"Joining the PyBites Platform and utilizing the code challenges in the PyBites Python Tips book has increased my Python skill set is relatively short time while constantly keeping me challenged. Tip #73 helped me with pulling in multiple files to analyze data, a great opportunity to automate a repetitive task I perform on a daily basis. It's very empowering to work through the code challenges and be able to put them into real world practice. Thank you Bob and Julian for bringing together this amazing community!" - Beth B
"They did it again. A new cool product! I enjoy everything PyBites does. Minimalistic approach and team work creates value! I read Bob's posts on Python tips and try to put in practice. When Bob and Julian announced their new book, I was so happy – no need to take screenshots as a madman! 😊 The best is that purchasing their book I could download the code and save it in my utils." - Alex K
"I have been reading your new Python Tips book for a little while now, just one tip per day along my #100DaysofCode journey. I really love the crisp, practical examples and the links to further reading. The book was indeed a steal. Looking forward to more tips!" - Andreas J
"The book is a great and handy reference covering a wide array of topics, from Python's standard library to 3rd party tools, such as howdoi, requests and imagio, just to name a few. The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H
"The PyBites book has me saying, "oh, I used this", "this is new". Great book, for me a Python newcomer and I'll be using it as a reference book!" - Israel L
"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier. I've been a member of the PyBites site for a few months now, and have always enjoyed getting the tips that you get after completing each bite. I've been taking notes for quite a while and would add each tip into my notes, but having them in book form is like having my own personal index of useful tips. Just today, I used an aspect of sets (set.difference) to help me solve a problem I was working on. Without that, I would have had to do a bunch of looping and conditional statements, but thanks to going through the PyBites Tips book, I remembered this set method that I had forgotten about. There are so many more tips just like this in the book, and they are continually adding to it! I'm still going through the book and am looking forward to the release of the new tips as well." - Jesse B
"The PyBites Python Tips book has been very helpful to me in my coding. Pythonistas of every skill level will find that a small investment of time, with this excellent book, will yield big dividends. Buy it now!” – Andrew J
"Need some great, helpful tips? Want quick examples how to use itertools? I've been getting the PyBites tips through twitter for a long time. Now 100 of them (more to come) are easily accessible in this extremely affordable e-book. Great collection! Thanks!" - Bart H
"This book should be in every Pythonista's arsenal, regardless if you're a professional developer or hobbyist. I use the PyBites Python Tips book daily during my lunchtime at work; I just open it up and pick a random tip to read. In just a few minutes, I will have:
1) grasped the idiomatic pythonic way of doing something,
2) understood the explanation behind the tip and opened up a heap of suggested browser links to investigate more about the topic,
3) typed out the few lines of code provided, cementing the knowledge gained, and finally,
4) tested myself by applying it to solve a PyBites exercise.
The wealth of knowledge this book provides compounds daily and I've enjoyed learning about the Python built-in standard library and many 3rd party tools too, all in a very approachable and practical way.
This is now my favourite first Python go-to reference. If you don't get this book, you're seriously missing out!" - Anthony L
"You know all those tricks you pick up on the way to learning something? All those 'oh neat!' and 'I didn't know that' and 'that will save me a TON of time' tidbits that you accumulate along the way? Well Bob and Julian made an entire book out of their amazing python tips and it's fantastic! Flip to any page and you will learn something new and get an exercise to test out your new knowledge to boot!" - Chris W
"I first started really using Python about 5 or 6 years ago when I undertook a MSc in Analytics. Once I’d completed my Masters I let my new Python skills slowly deteriorate through lack of use and this bothered me. When I discovered PyBites nearly two years ago I found a medium through which I could once again immerse myself in Python. I loved the targeted nature of the exercises and how you were encouraged to go and learn about parts of the Python Standard Library that you may not have been aware of. So when I heard that Bob and Julian were bringing out a book I knew that it would be a must have read, and I wasn't disappointed. The book is packed over 150 tips of Python wisdom, and growing, where each tip can be consumed and understood in a matter of minutes. Each Pythonic nugget gives clear and concise example code and also links to resources where you can go deeper if you want further explanation of the concepts. The tips show you the libraries and patterns you should be using in your everyday Python use and is also a great reference for when you know the command that you want to use but can’t quite remember the right syntax. Now you’ll be able to quickly refer back to your go to solution again and again and again. Congratulation to Bob and Julian on the release of this book which continues their great work promoting Python to an ever increasing audience." - David C
"The book is really awesome. It provides some really great insights on the vast Standard Library and the external packages. Every time I feel stuck on a problem and I need some clarification on possible methods, I refer to the book." - Gabriel S
"A great companion! I keep this book on my desktop so I can refer to it quickly and even browse through it for fun in my spare time. Since I'm new to python, it's nice having a collection of useful tips curated by folks with much more experience than me. It gives me the confidence knowing that the solutions within are good ones, which is not always the case when searching the web for answers. For that reason alone, I feel this book gives tremendous value. I've already used several tips in my personal projects and at work. Thank you, Bob and Julian for this!" - Ed G
Try it yourself, at our risk
We believe so strongly in this book and the gold within that we’re willing to take the full risk.
If, after reading it, you find you’ve not learned at least 1 or 2 new things (within 30 days of purchase), we’ll happily refund you the complete price of the book. No questions asked AND you get to keep the book.
Lock in future updates
But there’s more!
You’re actually going to get many more tips over the coming months!
Although the current collection of 200 tips is already profound and will surely help you up your game, by buying this product you will lock in any future updates, even as we increase the price.
For your investment of $6.99 USD today, you will actually end up owning 300 quality tips over the lifetime of the book. As we add more tips to the book though, we will be increasing the price so make sure you lock in your future updates at this introductory launch price.
What are you waiting for?
Enough reading (of this page)! Scroll back to the top and click the "I want this" button now!
Who is this book for?
Anyone interested in Python. The book may have more intermediate concepts but if you're a beginner, being exposed to these libraries, tools and concepts is going to get you experience with the language much faster.
Why is the Kindle version slower to launch?
It takes time to convert the base eBook/PDF version to Kindle (.mobi) format. In an effort to get you the eBook quicker we push it out first while the Kindle version is being created.
Will there be a print version?
Eventually, yes. As we mentioned above, we will be adding tips to the eBook over time. We're refraining from publishing a physical, print book until all tip updates have been made. This will avoid people having to purchase the print book again and again just to get the updates.
Why the super low price?
We wanted to make this content accessible to as many people as possible all over the world. The "low" price allows people in countries where currencies aren't as strong to access the value within.
Why was I given license key when I purchased the book?
Treat this license key like you would the key you receive when you purchase a software product. This is your proof that the "copy" of the book you have is yours. No need to register it anywhere, just keep it a record of it.
Are the exercises mentioned in the book included?
The short answer is no.
On occasion we mention a "Bite Exercise" on our platform as related material. This link takes you to our Python Challenges platform which is subscription based. If you have an active subscription you'll be able to starting coding the exercise right away. If not, you'll be able to create an account and activate a two week free trial to access the exercise.
You've purchased this product
See it in your libraryView in Library
We charged your card and sent you a receipt
You'll need an account to access this in our app. Please create a password to continue.
Download from the App Store or text yourself a link to the app
Thank you for purchasing PyBites Python Tips! Do us a favour and IMPLEMENT what you learn from it, don't just consume it. Then, share the good word so others know what you learned from the book! This is quality Python content we'd love to see in every Python programmer's toolkit. Thank you for your support :) -- Bob and Julian
Good news! Since you already have a Gumroad account, it's also been added to your library.