Discover and read the best of Twitter Threads about #PythonStdLib

Most recents (7)

Today is a great day to learn about #Python's `argparse` module!

The argparse module makes it easy to write user-friendly command-line interfaces.

#PythonStdLib 🐍πŸ”₯

πŸ§΅πŸ‘‡
Here is an example of creating an argument parser with no arguments.

Why would you do that? Well, to find out what `argparse` gives you out of the box πŸ“¦!

You can see here that `argparse` gives you some help text and prints out your provided description Image
A common coding pattern for argument parsing is to put the argument parsing code into its own function or method and then return the parsed args.

Here's an example: Image
Read 8 tweets
#Python includes more than 200 modules as a part of its standard library.

Today we will look at the `atexit` module

#PythonStdLib 🐍πŸ”₯

πŸ§΅πŸ‘‡
The `atexit` module in #Python defines functions to register and unregister cleanup functions.

Read more about `atexit` in the docs πŸ“š here:

docs.python.org/3/library/atex…
The Python docs have several interesting examples of using the `atexit` module.

Here is a module that can initialize a counter from a file when it is imported and save the counter’s updated value automatically when the program terminates
Read 4 tweets
Did you know #Python has a `cmd` module? It "provides a simple framework for writing line-oriented command interpreters."

According to the docs, `cmd` is "useful for test harnesses, administrative tools, and prototypes"

#PythonStdLib 🐍πŸ”₯
I personally have never used #Python's `cmd` module and I am not sure how I would use it.

However, the Python docs have an example that wraps Python's turtle module and creates a kind of shell interface to it:
You can grab this code and see its output here:

docs.python.org/3/library/cmd.…
Read 4 tweets
#Python added the `zoneinfo` module in 3.9, which provides a concrete time zone implementation to support the IANA time zone database.

You can learn more about it in PEP 615

python.org/dev/peps/pep-0…

#PythonStdLib 🐍πŸ”₯

πŸ§΅πŸ‘‡
Here is an example of using Python's `zoneinfo` module 🐍πŸ”₯
Here's another example of how you can from CDT to other timezones in the USA with #Python
Read 4 tweets
Module number 3️⃣ on our #Python standard lib tour is `argparse`

The argparse module makes it easy to write user-friendly command-line interfaces.

#PythonStdLib 🐍πŸ”₯

πŸ§΅πŸ‘‡
Here is an example of creating an argument parser with no arguments.

Why would you do that? Well, to find out what `argparse` gives you out of the box πŸ“¦!

You can see here that `argparse` gives you some help text and prints out your provided description
A common coding pattern for argument parsing is to put the argument parsing code into its own function or method and then return the parsed args.

Here's an example:
Read 8 tweets
The aifc module in #Python will be deprecated in Python 3.11

But it's still worth knowing about because so many people will still be able to use it.

This module provides support for reading and writing AIFF and AIFF-C files

docs.python.org/3/library/aifc…

#PythonStdLib 🐍πŸ”₯

πŸ§΅πŸ‘‡
AIFF is Audio Interchange File Format, a format for storing digital audio samples in a file. AIFF-C is a newer version of the format that includes the ability to compress audio data.

You can read and write these files with #Python using the aifc module!
When you go create an AIFF file with #Python, you use much the same type of code as you would when you use Python's `wav` module.

Here's an example:
Read 5 tweets
#Python comes with lots of modules. Let's get started by looking at the `abc` module.

The `abc` module isn't for learning the alphabet! It's for creating Abstract Base Classes 🀯!

Let's learn more about those now πŸ§΅πŸ‘‡

#PythonStdLib 🐍πŸ”₯
Abstract base classes (ABCs) are defined in PEP 1139.

You can read all about them here:

python.org/dev/peps/pep-3…
Abstract Base Classes in #Python provide the following:

🐍 A way to overload isinstance() and issubclass().
🐍 A new module abc which serves as an β€œABC support framework”.
🐍 Specific ABCs for containers and iterators, to be added to the collections module.
Read 9 tweets

Related hashtags

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!