Posts

Showing posts from July, 2025

Build it, Break it, Remake it

Image
After all the work and sweat put into making my Python output look good, the time has come to tear it apart and rebuild. Why? Because the code is a disorganized mess. Functions and variables were created on the fly without any future-looking structure. There is no sustainable way of going forward with it. Much as it hurts, it's time to throw away the original baby with its dirty bath water and begin again. I owe part of my courage to this guy, Pete the Web Developer . He encourages us to build before we're ready and to learn from our mistakes. What was my number one mistake? (1) I didn't organize my code into logical modules. Mainly because I was afraid of making my own modules. Turns out my fears were misplaced. "Module" is merely a fancy alias for a (dot) Py file. You put some variables and/or functions into a separate Py file and suddenly it's a "module".  Afzal teaches how to store global variables and retrieve them where needed here: ( global va...

Code Beauty Trumps that of the Display Output

Image
  Skin Deep or Deeper? Don't get me wrong. Having a pretty output on your display is important. However the fundamental point of using a higher level programming language is that its source code provides useful guidance to your brain (meaning to the brain of you as a code writer). You want your code to be both self-descriptive and yet at the same time as simple as possible so that you can instantly understand what the basic goal of each code section is. Here we enter the realm of Python Shallow Assignments and namespace aliases  Say that you name your functions and variables as descriptively as possible by using very long names (VLN's). The reason for this is that in the future, merely reading the initially assigned name of that specific function or variable gives you a good hint as to what that function or variable is supposed to do, at least at a relatively high level. In some of my code files, I have a function named qif_inStr_OK(arg1, arg2, arg3) where arg1 is named inStr ...

Frustrated? Keep Digging. Don't Quit

Image
  I sometimes pontificate to others on Reddit's r/learnpython that frustration is good. It makes you angry. Anger is a strong emotion. A motivating emotion. It nags at you all night long. You wake up in the middle of the night thinking you finally have the answer. You run to the terminal and furiously type in your new idea. Alas, no! That idea didn't work either! Damn. Maybe I should just give up?  Another day. Another night. You scour the internet. Surely others have faced the same problem. If only I can properly phrase my Google search or AI prompt to find their solutions! ( BTW, image on the right is from Easy-Peasy.AI )  Well, today, I had to eat my own humbling pie. The brilliant idea had occurred to me that I could dynamically attach COLORAMA commands into my string printing using a function call and a dictionary translation. The COLORAMA module (class?) has three objects named "Fore" (for foreground color), "Back" (for background color) and "St...

Treating Myself Like a Returning Student/Customer

Image
 I write the notes, so to speak. Just like Barry Manilow  writes the songs , except that my songs are coded in Python. When I come back to a (dot)Py program that I, myself wrote, it seems that I should instantly remember what the heck I was thinking at the time of creation. But no. Of course not. Upon return, I'm just another customer entering the store for a first time. I have no recollection of having been the creator of the store some many eons ago. Accordingly, I should have the program greet me just as it would any new and unsuspecting customer entering the store (or just as any naïve student of Python entering the classroom). Here is what such a welcome mat can look like: First thing to note is that the above screenshot shows a rather primitive User Experience ( UI/UX ). No fancy GUI. No cool drop down menu. Recall however, that this blog is called "Old Man Learns to Code". I'm just starting to learn the ins and outs of Python possibilities. Yes, I...

Jumping the Stacks Shark

Image
  Another non-flattering progress report for me today. I didn't realize that " breakpoint() " automatically reports its line number and activates Python's built-in debugger, PDB. So instead, I dove into the world of the "inspect" module and of the "sys" module; both of which allow you to get the "frame" info of the code you are currently in, or one frame back in the stack, or even two frames back, or more if you need. That indeed constitutes jumping the shark . So here is some of the jumper code I added to my teach-myself program: import inspect import sys import os def brk(mssg): print(f'\n(X): We hit a debug brk(mssg) point at {gotten_line_numb_2back()}') print(f'(Y): PDB debugger commands: l=LIST, c=CONTINUE, pp var= PrettyPrint the specific var') print(f'(Z): Additional message: {mssg}\n') breakpoint() And next below is the function that produces the "gotten" line number, two fram...

Links for Python Noobs

Image
In my learning journey as a relative newbie I've been compiling the below list of links for BEGINNERS The below links, are in no particular order and include those posted on the   Reddit LearnPython thread or pulled from my Obsidian notes or otherwise found::          Legend :   [ B: stars/out of 5 for Beginners]                               [ I: stars/out of 5 for Intermediates] /                                [ A:  stars/out of 5 for Advanced coders]                               ---^^^--- Up carrots mean this line rel ates to above entry          - Intro: Which Language to Learn First ? UTTER BEGINNERS CAN START AT ONE OF THESE : ( Person...

Everything From Everywhere All At Once -- Doesn't Fly

Image
 Greed. That's the in-your-face word describing why self-taught coder wanna be's like me (wanna learn Python) get too close to the sun , melt, fall, and fail to reach their goal. There are just too many free and great tutorials available on the Internet. The urge is to learn every detail possible about Python all at once. I want to understand that one now. No, I mean that other of infinite aspects now. No. I changed my mind for the Nth time today and found a new superseding desire.  Sundas Khalid characterizes it more politely as "information overload" in her video entitled "Why 99% of Self-Taught Programmers Fail" ( here ). Whatever we call it, it's the road to ruination. We grab for too much chocolate before having gained mastery of the fundamentals. And that applies to my current progress report. I've been jumping all over the place instead of sticking to learning the fundamentals, like getting mastery over the more important string methods, lis...

Missing the Big Sweat Globs on account of focus on the Small Stuff in them

Image
  The two previous posts (here) and (here) did not go as planned. Too much caught in the details (in the weeds) and then no time or energy for pointing out the big picture --or more correctly answering the subsuming question, which is: Why would I want to skip some of the tutorial exercises in my "Learn or Review List Methods" Python program in the first place? By the way, it worked. I converted the first tutorial into a function and put in a conditional return based on one of the items in my skip_diz list. Here is part of the code: TO BE CONTINUED  def choice_of_die_outcomes(method_ID_numb, method_name, verb, skip_diz_list_a): #-- last arg is a skip control if skip_diz_list_a[method_ID_numb] == 1: print(f'method number {method_ID_numb} has been skipped\n') return None #--skip this tutorial if skip position for tutorial 01 is set to 1 face_imgs_row1 = ['🤬', '🧐', '🤓🤓', '😲...