Mike Driscoll Profile picture
Feb 15 6 tweets 3 min read
Today is a great day to talk about one of #Python's most popular SQL ORMs - SQLAlchemy!

SQLAlchemy is an Object Relational Mapper for Python. That means that it can translate Python code to SQL.

🧵👇🐍
Let's take a look at creating a database with #Python and #SQLAlchemy

You need to create classes that model tables in your database.

Then to create the actual database, you use `Base.metadata.create_all()` Image
Now let's add some data to our database using #Python and #SQLAlchemy

The following code shows how to add data to both our tables. It also shows how to add multiple rows of data all at once! 🐍🔥 Image
Now that you have data in the database, let's find out how to write a simple query and change one of the fields!

Here are a couple of examples that demonstrate how to change two different fields in your database: Image
To wrap things up, let's look at how you might delete a record from a database using #Python and #SQLAlchemy Image
Thanks for reading my thread on Python and SQLAlchemy. Working with databases can be fun in Python!

• • •

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

Feb 18
Today we are going to talk a little about creating command-line applications using #Python and its built-in `argparse` package!

🧵🐍👇
In this example of using `argparse`, you don't even create any custom arguments! You just create an ArgumentParser argument and call `print_help()`!

You can see in this example that `argparse` already provides useful information to your users without adding any arguments! Image
Normally when you create an `ArgumentParser` object, you would do so in a function and return the object.

Let's rewrite the previous example to follow that coding pattern: Image
Read 11 tweets
Feb 17
Even if you are a beginner, you have probably used #Python's built-in `print()` function.

But let's take a few minutes to talk about the humble `print()` function and see what you might have missed!

#python_builtins_by_driscollis

🧵🐍👇
The `print()` function takes the following arguments:

🐍 *objects - Stuff to print
🐍 sep=' ' - A string to separate object
🐍 end='\n' - A string to end on
🐍 file=sys.stdout - Where to write the data
🐍 flush=False - Whether or not to force flush the stream
Let's look at some examples of using Python's `print()` function: Image
Read 5 tweets
Feb 17
#Python has an awesome library called `collections`! One of my favorite tools from that library is the `Counter` class.

Here I use `Counter` to find the most common occurrences of a value in a list: Image
Let's use `collections.Counter()` to count letters in a string!

Note that the object that is returned by the Counter class can be accessed like a dictionary! Image
Python's `collections.Counter()` class has special methods that you can use to `subtract()` items from the counter object.

Here's an example: Image
Read 4 tweets
Feb 16
If you want to use #Python to read and write text or binary files, then you'll need to familiarize yourself with the built-in `open()` function!

Join me for this thread to learn more!

#python_builtins_by_driscollis

🧵🐍👇
#Python's `open()` function actually has quite a few different parameters that you can use: Image
The most commonly used parameters you will use with #Python's `open()` function are:

🐍 file - The path to the file
🐍 mode - Read, write, binary, etc
🐍 encoding - What encoding the file is in
Read 8 tweets
Feb 16
We have already learned about the `bin()` and `hex()` functions. Today you will learn about #Python's handy `oct()` function!

`oct()` is used to convert an integer number to an octal string prefixed with “0o”

#python_builtins_by_driscollis

🧵🐍👇
Here are a couple of examples of using the `oct()` function with positive and negative numbers: Image
The #Python documentation has a nice example that shows how to format octal numbers using string formatting: Image
Read 4 tweets
Feb 15
Blockchain is a super popular topic here on Twitter. While I am not a blockchain developer, I thought it would be fun to put together a short thread on blockchain and #Python

Check it out if you're interested in this topic!

🧵🐍👇
ActiveState is a well-respected #Python company with lots of great content and they have an intro article on blockchain with Python:

activestate.com/blog/how-to-bu… @ActiveState
@ActiveState The GeekFlare website also has a popular article on creating a blockchain with #Python:

geekflare.com/create-a-block…
Read 7 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!

:(