Python

Last updated on

Python is my most studied programming language, so I new a few things here and there. Here are my notes:

Learning resources

Through my learning path, I came across with multiple resources, both good and bad. This list are my recommendations, for there are quite a few places to learn python out there in the wild.

YouTube channels

Youtube is an excellent platform, but not without its downsides: It’s so full of courses.

  • mCoding is an excellent resource with Python and C++. James Murphy offers consulting, contracting and training of his languages with great examples and really good practices.
  • ArjanCodes is an empathic well-versed programmer. It also has a Discord which is full of interesting threads and people.
  • Anthony Sottile is a respected coder in the Python ecosystem. He streams regularly in Twitch and VODs are uploaded in YouTube

Resources

  • This specific video by James Powell “So you want to be a Python expert” is insightful, even if you don’t understand most of the features that are mentioned in the video. Watch it for the plot. The other videos by James Powell aren’t very thoughtful but they can help you in a thing or two.
  • Python’s dunder methods, or magic methods:
    • Python magic methods are known by everyone (__init__ for example).
    • You can find an explanation of what dunder methods are by TechWithTim here.
    • And Arjan talks about when not to use them here.
  • types, typing, typing anotations and more:

Tools

  • Black is the formatter

  • ruff is my preferred linter. It includes the lints from flake8, and isort!

  • You wish a debug print like in rust? here, Samuel Colvin delivered.

  • writing a CLI app? take a look at typer

  • do you use a SQL db? make sure you read through sqlmodel

  • PrettyErrors turns Exceptions into a beautiful poem.

  • bpython is a colorful REPL for python. Unfortunately only works for POSIX systems.

  • Raw SQL, SQL Query Builder, or ORM? Arjan gives a comprehensive view of all the options available.

  • FastAPI is by far the easiest and quickiest way to build a RESTful API.

Tips and tricks

I have loads of tips and tricks. I will try to jot them down as I remember all of them:

  • you can print the variable and it’s value with this syntax
# if you put a variable and = after that
print(f'{str_value = }')
# prints the var and its value
# str_value = 'the contents of my variable'
  • you can run interactively your python program like the REPL with: python -i main.py

source: Python Quick Tip: Interactive Mode

This post comes from github, view it here