Weekly Python Coding Challenge

Christopher Franklin
Weekly Python
Published in
2 min readJan 2, 2021

Welcome to the first edition of the Weekly Python Coding Challenge! The rules are pretty simple, pick one of the challenge projects below and complete it this week. Next week’s email will include a link to an example implementation so you can evaluate how well you did.

Without further ado, your challenge this week is to create a python application to list all files in the current directory.

Beginner Project: As a beginner, you should use this project to familiarize yourself with the ‘os’ module in python. You will need to familiarize yourself with the concept of a “directory” and a “current working directory”.

Your challenge is to create a python script that will print the names of every file in the directory you run it from in alphabetical order. For this challenge, we only want to see the names of files and not include folders in the returned list. Also, make sure the list is printed with one file per line of output.

Beginner Stretch Goal: Add a command-line argument to also include the names of every folder in the current working directory.

Intermediate Project: Intermediate developers should already be familiar with the basics of the ‘os’ module, so your challenge is to turn this into an installable CLI (Command Line Interface) tool.

You may use any of the many CLI libraries to assist in building this application. As a minimum product, your CLI tool should be able to run without any arguments and just list the contents of the current directory. As an added challenge, make the output print in a multi-column format similar to the output of the ‘ls’ command on Linux based systems. You should also allow an argument that points to the directory you want to print the contents of.

Intermediate Stretch Goal: Add an option to list the details of the files, line-by-line. For example, list the file size, created date, owner, etc. Print the results in a multi-column table, with each file on its own line.

Advanced Project: Recreate the ‘ls’ command from scratch and add some modern twists. Colorize the output to make it easier to read, show all extended attributes, allow the “long view” attributes to display multiple columns if the terminal is wide enough. The ‘ls’ command does a LOT, so implement as much of it as you can in the next week!

Advanced Stretch Goal: Use asyncio to concurrently gather extended attributes of each file and improve performance. You need to build on Python 3.7+ to take advantage of this.

Now, get out there and program!

Chris Franklin
Weekly Python

P.S. Remember, if you complete one of the challenges and found it easy, try the next level up!

P.P.S. Want more weekly coding challenges? Sign up for the newsletter to get them directly in your inbox: https://weeklypython.substack.com/welcome

--

--