Sitemap

Python: Getting comfortable

2 min readMay 2, 2023

--

We are going to be walking through the tasks at hand for this project.

Press enter or click to view image in full size

What is Python?

Python is a computer language that people use to talk to computers in a specific manner that allows the computer to understand. Python can be used for building websites, analyzing data, and automating tasks.

A few examples of when python is being utilized would be app development, data analysis, automating tasks, and desktop applications.

Scenario: Your company needs to learn about the files located on various machines. You have been asked to build a script that extracts information such as the name and size about the files in the current working directory and stores it in a list of dictionaries.

Get Maddie Padgett’s stories in your inbox

Join Medium for free to get updates from this writer.

We will be utilizing cloud9 as our platform as we navigate our way through the project

  1. Create a script that generates a list of dictionaries about files in the working directory. Then print the list.
#!/usr/bin/env python3.7

import os

# Get the current working directory
cwd = os.getcwd()
current_dir = os.getcwd()

# Create an empty list to store the file information
file_info = []

# Walk through directory tree and get file information
for dirpath, dirnames, filenames in os.walk(current_dir):
for file in filenames:
file_path = os.path.join(dirpath, file)
file_size = os.path.getsize(file_path)
file_info.append({"name" : file, "size" : file_size})

# Print the list of the file information
for file in file_info:
print(file)
Press enter or click to view image in full size

I put the code into a file from the python template.

Now we print the list:

Here is a show of files printed names and with the size as well.

Press enter or click to view image in full size

2. Push your code to GitHub and include the link in your write up.

This seemed to be the trickiest part for me, I kept having to revisit the demo in order the remember the steps for cloning the repo in the right place.

Here is the final product!

https://github.com/mfpnrl/gold-member/blob/main/week13project.py

--

--

Maddie Padgett
Maddie Padgett

Written by Maddie Padgett

Cloud Engineer | Transitioning from Director of Communications