Mike Driscoll Profile picture
Jul 1 4 tweets 2 min read
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.…
Part of me wonders if you might be better off writing something like this with Textual instead.

I don't really know, but it's an interesting module and something to keep in mind.

• • •

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

Jul 1
If you're new to #Python and you want to install a Python package from the Python Package Index, you will probably want to use pip

Pip comes with Python (except where Python is preinstalled, like Linux)

I'm going to talk a little about what you can do with pip

🧵👇
Installing a #Python package with pip is usually as simple as running the following: Image
Sometimes you may want to install multiple #Python 🐍packages. You can run the command for each package or you can separate the names of the packages with spaces: Image
Read 8 tweets
Jul 1
I am always being asked what to do after learning the basics in #Python

Here's a short thread on the topic!

🐍🧵👇
There are lots of places to find ideas. My friend, @learn_byexample has some great stuff here:

learnbyexample.github.io/practice_pytho…
Another of my friends, @AlSweigart , has an entire book of #Python projects:

inventwithpython.com/bigbookpython/
Read 7 tweets
Jul 1
Hi! 👋

I'm Mike! I write about #Python 🐍🔥

I create books, write tutorials, publish videos, and tweet about Python!

I cover the following topics:

🐍 Python basics
🐍 Python GUIs
🐍 Automation
🐍 Python & Excel
🐍 Python & PDFs
🐍 Python and Images
🐍 and lots more!
Check out my website for HUNDREDS of #Python 🐍 tutorials:

blog.pythonlibrary.org
I have lots of #Python content on YouTube and I am going to add LOTS more:

youtube.com/c/MouseVsPython
Read 5 tweets
Jul 1
Today is a great day to learn about exception handling in #Python!

Let's find out how they work!

🧵🐍👇
#Python handles exceptions using the `try/except` keywords.

You can optionally add `finally` and `else` to the mix too!

Here's an example that uses all of them: Image
#Python has the concept of the "bare except". What that means is that you catch ALL exceptions.

You can do this by catching Exception, which is the base class of ALL other exceptions.

Or you can just not specify an exception type all! Image
Read 15 tweets
Jun 30
#Python has many different GUI Toolkits. In this mini-thread, I'm going to show you how to write a "simple" plot with #wxPython

🧵🐍👇
Creating a plot with #wxPython doesn't take a TON of code, but most GUI frameworks do require a LOT more code than simple scripts.

Here is a pretty stripped down plotting example:
When you run the code in the previous tweet, your #Python graph will look like this:

#wxPython 🔥
Read 4 tweets
Jun 29
Did you know #Python has a built-in way to chain multiple dictionaries together?

It's called `ChainMap` and it's part of the `collections` module.

Let's talk a little about it today!

🧵🐍👇
A ChainMap takes one or more mappings or dictionaries and combines them into a single unit.

When you do this, the ChainMap will go through each map in order to see if that key exists and has a value. If it does, then the ChainMap will return the first value it finds. 🐍🔥
Let's look at an example of using `ChainMap` in #Python
Read 6 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!

:(