Share
 

Hey Pythonista,

Happy Tuesday!

Here are our 5 bullets of the week:

1) How to deal with distraction and better focus?

It's easy to get distracted in this day and age, and for software engineers this is even more perilous because our success comes from long uninterrupted time slots.

2 resources that might help you with this:

A. Paul Graham's Maker's Schedule, Manager's Schedule essay: https://paulgraham.com/makersschedule.html

B. Cal Newport on the Tim Ferriss podcast: https://tim.blog/2024/02/21/cal-newport-slow-productivity/

Newport's Deep Work we've mentioned a lot, it's a staple.

I (Bob) am also reading Digital Minimalism now, it's an eye-opener! There is way more distraction in our lives than 10-20 years ago, mainly caused by internet + mobile phones, so be deliberate how and where you focus your precious attention.

2) concurrent.futures

Some people shy away from learning Async IO, which yes, is not the easiest Python feature to pick up.

But did you know you can also achieve concurrency with other libraries, even Standard Library ones, quite easily?

Here is an example from the concurrent.futures docs how to use `ThreadPoolExecutor` to significantly speed up downloading articles. 🐍 📈

(This example uses requests, make sure you check its Session object as well, or check out the newer httpx library.)

```
# full code: https://gist.github.com/pybites/6a15bfe006057b6d82e85b4fd1240beb
import concurrent.futures
import os
import requests

def _download_page(url):
    fname = os.path.basename(url)
    r = requests.get(url)
    with open(f'downloads/{fname}', 'wb') as outfile:
       outfile.write(r.content)

def download_urls_sequentially(urls):
    for url in urls:
        _download_page(url)

def download_urls_concurrently(urls):
    with concurrent.futures.ThreadPoolExecutor(max_workers=32) as executor:
        future_to_url = {executor.submit(_download_page, url): url
                         for url in urls}
        for future in concurrent.futures.as_completed(future_to_url):
           future_to_url[future]

$ time python dl.py -s
real 0m51.322s

$ time python dl.py -c
real 0m2.878s
```

3) Podcast updates

Stay tuned for our episode with Paolo Melchiorre (paulox) later this week, a longtime Python backend developer who contributes to the Django project and gives talks at tech conferences.

And last week's episode with coach Hugh interviewing Julian was really well received.

Julian shared the triumphs and trials of building Pybites, highlighting the significant milestones from the first subscriber to facing the tech industry's fast-paced and evolving landscape. 💡

We learned about the critical role of mindset in overcoming obstacles and achieving growth, not only within Python but in personal and professional realms.  📈

Plus, Hugh and Julian spoke about Pybites' vision for the future, including innovative initiatives for veterans, efforts to introduce coding to school-aged children, and more... 😍


Talking about podcasts, Bob also got on the Real Python podcast last week to talk about "building a healthy developer mindset while learning Python".


4) Thank you, guest authors, 😍 🙏

Last week we published 3 new articles:

1. Build a route planner for maps using Python, by Judith Vockenroth

Explore the future of navigation with Judith's innovative route planner detailed in this article.

This application leverages Overpass API and OpenStreetMaps to offer routes tailored not just to distance, but also to preferences like illumination and quietness. Users can easily choose between the shortest or quietest path, with the application calculating the optimal route using advanced algorithms.

Beyond mere navigation, this tool introduces a new layer of customization to urban travel, enhancing safety and comfort. Discover how to make your journeys more personalized and enjoyable with our step-by-step guide.


2. Case Study: GitHub Copilot and the deceiving ladder, by Michael Aydinbas

Can GitHub Copilot be used to solve mathematical puzzles? What to be aware of when AI assistants are too confident? Interesting and in-depth case study article by Michael - enjoy!


3. A Better Place to Put Your Python Virtual Environments, by Ahmed Lemine

Most Python developers put the virtaulenv (or venv) inside the project folder. It's a common practice and the default location for the project venv.

In this article Ahmed goes over the downsides of this approach and he suggests keeping all venvs in one place and the reasons why he thinks it's a better solution.


Thanks Michael, Judith and Ahmed for all the hard work.

And stay tuned for more articles.

5) Are you using Python's built-ins enough? (From the archives ...)

Stop reinventing the wheel, embrace Python built-in functions!

Examples:

  • Built-in functions like 'len()', 'sorted()', and 'max()' are your friends. Instead of writing loops to calculate the length of a list, sort data, or find the maximum value, use these one-liners that Python provides out of the box

  • Dictionaries in Python come with handy built-ins like '.get()' and '.items()' which help avoid KeyError and simplify iteration, respectively. No need to write extra checks or unpacking logic.

  • Set operations can greatly reduce the complexity of your code. Using built-ins such as '.union()', '.intersection()', and '.difference()' to handle unique elements can eliminate the need for loops or conditional checks.

  • The 'any()' and 'all()' functions allow for concise conditional expressions. Instead of writing an explicit loop to check for a condition within an iterable, these built-ins can produce the same result in a cleaner way.

See also our "Useful Python Built-in Functions" video on this topic: https://www.youtube.com/watch?v=ejvql4eKev4

---

Hope those tips and resources are helpful for you. Now get out there and smash it this week.

Best,
Bob & Julian


P.S.

Are you interested in learning more tools to improve your Python skills?

Is your passion writing Python code with a hope to transition into a Python developer role someday?

Do you already have decent coding skills, but struggle with putting it all together?

And even if you can follow a tutorial just fine, do you find that you never have the confidence or just don't know how to use what you've learned?

That's where our coaching comes in!

Check out our programs and get in touch if you want to work with us addressing those issues in an efficient manner:


Email Marketing by ActiveCampaign