Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

#43: Python string theory, v2

Published Thu, Sep 14, 2017, recorded Tue, Sep 12, 2017

Python Bytes 43

This episode is brought to you by Rollbar:

Brian #1: future-fstrings

  • A backport of fstrings to python < 3.6
  • Include an encoding string the top of your file (this replaces the utf-8 line if you already have it)
  • And then write python3.6 fstring code as usual!
        # -*- coding: future_fstrings -*-
        thing = 'world'
        print(f'hello {thing}')
  • In action:

        $ python2.7
        hello world
  • I’m still undecided if I like this sort of monkeying with the language through the encoding mechanism back door.

Michael #2: The Fun of Reinvention

  • Keynote from PyCon Israel
  • David Beazley rocks it again
  • Let’s take Python 3.6 features and see how far we can push them
  • Builds an aspect-oriented constraint system using just 3.6 features

Brian #3: Sound Pattern Recognition with Python

  • to read a .wav file.
  • Looking for peaks (knocks).
  • Using minimum values to classify peaks, and minimum distance between peaks.
  • This is an interesting start into audio measurements using Python.
  • Would be fun to extend to some basic scope measurements, like sampling with a resolution bandwidth, trigger thresholds, pre-trigger time guards, etc.

Michael #4: PEP 550: Execution Context

  • From the guys at
  • Adds a new generic mechanism of ensuring consistent access to non-local state in the context of out-of-order execution, such as in Python generators and coroutines.
  • Thread-local storage, such as threading.local(), is inadequate for programs that execute concurrently in the same OS thread. This PEP proposes a solution to this problem.
  • A few examples of where Thread-local storage (TLS) is commonly relied upon:
    • Context managers like decimal contexts,numpy.errstate, and warnings.catch_warnings.
    • Request-related data, such as security tokens and request data in web applications, language context forgettext etc.
    • Profiling, tracing, and logging in large code bases.
  • The motivation from uvloop is obviously at work here.

Brian #5: Intro to Threads and Processes in Python

  • Beginner’s guide to parallel programming
  • Threads and processes are both useful for different kinds of problems.
  • This is a good quick explanation of when and where to use either. With pictures!
  • Threads
    • Like mini processes that live inside one process.
    • Share mem space with other threads.
    • Cannot run simultaneously in Python (there are some workarounds), due to GIL.
    • Good for tasks waiting on IO.
  • Processes
    • Controlled by OS
    • Can run simultaneously
    • Good for CPU intensive work because you can use multiple cores.

Michael #6: Alternative filesystems for Python

  • PyFilesystem: Filesystem Abstraction for Python.
  • Work with files and directories in archives, memory, the cloud etc. as easily as your local drive.
  • Uses
    • Write code now, decide later where the data will be stored
    • unit test without writing real files
    • upload files to the cloud without learning a new API
    • sandbox your file writing code
  • File system backends
    • AppFS Filesystems for application data.
    • S3FS Amazon S3 Filesystem.
    • FTPFS File Transfer Protocol.
    • MemoryFS An in-memory filesystem.
    • MountFS A virtual filesystem that can mount other filesystems.
    • MultiFS A virtual filesystem that combines other filesystems.
    • OSFS OS Filesystem (hard-drive).
    • TarFS Read and write compressed Tar archives.
    • TempFS Contains temporary data.
    • ZipFS Read and write Zip files.
    • and more

Our news

Michael: switch statement extension to Python:

Want to go deeper? Check our projects