Mike Driscoll Profile picture
Jun 3 β€’ 4 tweets β€’ 2 min read
Did you know that #Python has a `slice()` function! 🐍

Let's learn more about that now!

πŸ§΅πŸ‘‡πŸ
The `slice()` function returns a slice object representing the set of indices specified by `range(start, stop, step)`

Read more in the #Python docs here:

docs.python.org/3/library/func…
You can use the `slice()` function to created NAMED SLICES in #Python!

Here's an example:
Isn't that a cool feature? The slice can be used by #NumPy and other third-party #Python packages.

I probably won't use it much, but it's neat to know that it's there!

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Mike Driscoll

Mike Driscoll Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @driscollis

Jun 5
#Python has had the concept of context managers for a loooong time!

Let's talk about context managers again!

πŸ§΅πŸπŸ‘‡
The `with` statement, which is the normal way for working with context managers, was added back in Python 2.5!

Here is a pretty common example of using a context manager: Image
The beauty of a context manager is that they allow you to do some setup and teardown automatically.

The downside is that is abstracted away and can sometimes make the code less obvious when debugging
Read 8 tweets
Jun 3
#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 🐍πŸ”₯ Image
Here's another example of how you can from CDT to other timezones in the USA with #Python Image
Read 4 tweets
Jun 1
Hi πŸ‘‹! I'm Mike!

I write about:

🐍 #Python
πŸ•ΈοΈ Python Web Frameworks
πŸ’¦ Python GUIs
πŸ€– Python & automation
πŸ“Š Python and data visualization
🐼 Python and data science
πŸ“š Indie publishing
πŸ“– Content creation
🐍 Python and PDFs
πŸ”₯ Python and Excel
πŸ–ΌοΈ Python & Images

and more!
If you like to learn by reading tutorials, you should check out my website @mousevspython 🐭🐍

blog.pythonlibrary.org
@mousevspython If you are a visual learner, then you might enjoy my YouTube channel:

youtube.com/c/MouseVsPython
Read 5 tweets
May 11
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
May 11
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
May 10
#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

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/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(