Skip to content

19th November 2021

Coding

Python

asyncio

Python Snippets

  • New: Remove a substring from the end of a string.

    On Python 3.9 and newer you can use the removeprefix and removesuffix methods to remove an entire substring from either side of the string:

    url = 'abcdc.com'
    url.removesuffix('.com')    # Returns 'abcdc'
    url.removeprefix('abcdc.')  # Returns 'com'
    

    On Python 3.8 and older you can use endswith and slicing:

    url = 'abcdc.com'
    if url.endswith('.com'):
        url = url[:-4]
    

Pydantic

  • New: Field customization.

    Optionally, the Field function can be used to provide extra information about the field and validations. Such as the title, default, description and many others

Tenacity

  • New: Introduce the Tenacity python library.

    Tenacity is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just about anything.