Name It and Claim It: Deleting Stocks and Wrestling Filenames

Day 57 of 100 Days Coding Challenge: Python

Yesterday, I made a small typo when entering a stock symbol—just one little slip of the keyboard, and suddenly I’m the proud owner of a fictional stock ticker. Unfortunately, the program didn’t come with an “oops” button, so today’s goal was obvious: build a function that lets me delete stock symbols from my list before my portfolio starts sounding like a toddler named it.

While I was at it, I got curious about filenames. You see, in the past, I’ve gone a bit wild with my naming convention—stuff like Book_Tracker_v2.py, final_final_please_work.py, or the classic version3_newest_final_backup2.py. This time, I wanted to test a more polished approach. I tried naming my file stock_tracker v1.1.py, thinking it looked quite professional. Spoiler alert: Python did not agree. Turns out, spaces in filenames are like pineapple on pizza—technically possible, but likely to cause arguments and strange behavior. Thankfully, stock_tracker_v1.1.py worked like a charm. I even read online that while dashes (-) are allowed, underscores (_) are generally the safer bet, especially if you want to avoid those sneaky bugs that only show up on Tuesdays after coffee.

Today’s Motivation / Challenge

Stock lists, like closets, need regular cleaning. If you accidentally track “TSLAA” instead of “TSLA,” your code won’t yell at you—but your future self will. Today’s challenge was all about giving the user (ahem, me) the power to tidy up their tracked stocks without digging through JSON files manually. It’s about building habits—and menus—that you can live with.

Purpose of the Code (Object)

This code lets you remove any stock symbol you’ve previously added. You just type the ticker you no longer want, and poof—it’s gone from the list. No editing files, no drama. The script also includes the option to view your list or exit gracefully (with a nod of thanks).

AI Prompt:

Write a Python program that allows users to delete a stock symbol from a JSON-based watchlist. The program should prevent duplicates, validate user input, and display a clean menu.

Functions & Features

  • Add new stock symbols to your list
  • View all currently tracked stocks
  • Remove a stock symbol by name
  • Quit the program (option 99, always last)

Requirements / Setup

Python 3.8 or higher

No additional libraries are needed. If you’re starting from scratch, create a virtual environment:

python -m venv venv

source venv/bin/activate  # macOS/Linux

venv\Scripts\activate     # Windows

Minimal Code Sample

def remove_stock(symbol):

    symbol = symbol.upper()

    stocks = load_stocks()

    if symbol in stocks:

        stocks.remove(symbol)

        save_stocks(stocks)

Removes a stock from your tracked list if it exists.

Stock Tracker

Notes / Lessons Learned

The trusty “Exit” option is still holding strong at number 99—right where it belongs. Tucking it at the bottom of the menu means no more accidental goodbyes when all I meant to do was clean up a typo. It’s like the emergency exit: always there, but hopefully not pressed by mistake.

Now, about filenames. I had this grand idea to name my script stock_tracker v1.1.py—you know, a classy versioning system worthy of a Silicon Valley pitch deck. Python, however, wasn’t impressed. Turns out, putting spaces in filenames is a little like trying to run a sprint in flip-flops. Technically doable. Practically… a terrible idea. After a few errors and some Googling, I landed on stock_tracker_v1_1.py, which behaved much better. Pro tip: underscores are your friends, hyphens are moody, and spaces are just asking for trouble.

Oh, and that rogue stock symbol I entered yesterday? Gone. Deleted. Justice served.

Optional Ideas for Expansion

  • Confirm before deleting a stock (a simple “Are you sure?” prompt)
  • Add auto-complete for stock symbols already in the list
  • Show a “last modified” timestamp next to each symbol

Leave a Reply

Your email address will not be published. Required fields are marked *