Stephen Gruppetta

Hello. Following a first career as a research scientist and University academic, I now focus on teach...  
Read more

Stephen's Collections

2021

Sep 25, 2021
Sep 25, 2021
Wrote a Blog Post
Wrote about Python
—You’ve written a Python script or project with several modules
—You press Run, figuratively or literally
—What happens behind the scenes in the microseconds or seconds or minutes it takes for your program to run?

You can dive into the details about the internal functioning of Python to learn how a Python program works.
But...there’s another way to visualise what’s happening.

Each blank Python file you create is represented by a room that’s mostly empty except for a few shelves on one of the walls and a small booklet named “built-in”. This booklet has some functions, constants, and other keywords in it.

Monty is a friendly, hard-working character who represents the computer program. He’s very fast and efficient, but you’ll need to spell out instructions clearly when you ask him to do something.

When you ask Monty to create a variable to store some information in, he’ll get an empty box and label it with the variable name you tell him. He’ll place whatever data you want in the box and place the box on one of the shelves.

If you’ve used an import statement, Monty will leave the room briefly to go to the library, where he’ll fetch a book with the name of the module you’re importing. He’ll take this book back to the room and place it on a shelf.

When you use any name in your script, Monty will look around the room to find that name. It may be a book (a module you’ve imported), it may be a box (a variable you’ve created), or it may be a name that’s inside the “built-in” booklet.

A function is a mini-program and is represented by a separate room—the function room—adjacent to the main room.

The door leading from the main room to the function room has a label on it. The name on this label is the function name.

When you call a function in your program, Monty will find the name of the function on the function room’s door. He’ll open the door and go through it. He may need to take some things with him as he goes to the function room. These are the arguments in the function call.

Monty performs all the tasks he’s asked to do in the Function Room and then returns to the main room, possibly bringing some information along with him. These are the items of data returned by the function.

Want to read more? This is the analogy I've developed to help me understand what's really happening "behind the scenes" when a computer program runs. You can read the full analogy here: Understanding How a Python Program Works
Sep 23, 2021
Sep 23, 2021
Published a book
Wrote a book chapter
Published Chapter 9 of The Python Coding Book about Dealing With Dates and Times in Python
Sep 15, 2021
Sep 15, 2021
Wrote a Blog Post
Published my latest article on using object-oriented programming in Python to simulate bouncing balls

A different take on an OOP example
Aug 30, 2021
Aug 30, 2021
Wrote a Blog Post
Wrote about Python
My latest tutorial on Real Python was published today

Using Python Optional Arguments When Defining Functions
Aug 30, 2021
Aug 30, 2021
Wrote a Blog Post
Wrote code
Wrote Python
Wrote about Python
+ 2
Published a long-form post/article on my blog on:

How to Create Any Image Using Only Sine Functions | 2D Fourier Transform in Python


This takes me back to a "previous life" when dealing with optics, and Fourier Optics, in particular, was my day job. I had written a version of this code well over a decade ago when I was diving deeper into Fourier Optics, and it was great to revisit the code–I actually wrote the whole thing from scratch as the old code was in Matlab and written by a much younger version of me!

It was so much fun writing it up into an article too. Hope you enjoy it. 

Aug 27, 2021
Aug 27, 2021
Wrote a Blog Post
You know how to use Python functions. But do you *really* understand Python functions?

Here's how to visualise what's happening behind the scenes when you define and use Python functions.
Get your own page like this