I tweet about everything #Python
Writing about Python @mousevspython @realpython
Teaching at @TeachMePy
Author of multiple books - https://t.co/MdP25zw5zQ
6 subscribers
Feb 1 β’ 8 tweets β’ 3 min read
Did you know that #Python supports SQLite in the standard library? That's right. You don't need to install anything! ππ
Let's talk a little about that!
π§΅π
If you have a pre-existing SQLite database file, you can use #Python's `sqlite3` module to connect to it
Here's how:
Nov 21, 2023 β’ 9 tweets β’ 3 min read
Today is a great day to talk about #Python lambdas!
Let's learn about them in a thread
ππ§΅π
A Python lambda is a one-line anonymous function.
Rule #1 is do NOT assign a lambda to a variable.
When you do that, it's no longer an anonymous function. You should just create a regular function at that point
Mar 23, 2023 β’ 4 tweets β’ 2 min read
Want to create a copy of a #Python list? Use Python's `copy()` method!
Note: Watch out if your list contains lists of dictionaries. In those cases, you might be better off using copy.deepcopy()
But be careful! If your list contains a mutable object, like another list or a dictionary, you may encounter some unexpected behavior.
In the following example, you `copy()` the list. Then you modify the nested dictionary in the copy, but that also changes the original list!
You can sort #Python lists in a couple of different ways. Find out how in this thread!
π§΅π
#Python lists come with a `sort()` method that makes sorting easy!
Jan 20, 2023 β’ 15 tweets β’ 7 min read
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:
Jan 20, 2023 β’ 4 tweets β’ 2 min read
You can use Pycryptodome to encrypt a file and decrypt it.
In this example, you use RSA encryption to encrypt a file with #Python
Now let's decrypt the file using Pycrytodome! ππ₯
Here's how to do it:
Jan 13, 2023 β’ 16 tweets β’ 7 min read
Today I am going to show you how to create 7οΈβ£ different file types with #Python:
π Text file
π CSV
π XML
π JSON
π Tar file
π PDF
π Excel
Join me for this fun π§΅π
1οΈβ£ Creating a text file with #Python is a breeze! The recommended method is to use Python's `with` statement as it will automatically close the file for you
That means you can create a text file with TWO lines of code if you want to:
Jan 11, 2023 β’ 10 tweets β’ 5 min read
#Python 3 has had asynchronous capabilities since 3.4. So let's talk about that today!
π§΅ππ
Your first stop when learning about async in #Python is the official documentation.
There you will learn about the following:
π The `asyncio` module
π The `async` and `await` keywords