Me too ! I seem to have forgotten everything

 

So, here I am, ...
confidently working up my next OOP project.

I get the idea that I wnat to see the latest directory of my newly defined class -- what methods have I created in here so far?

So use the dir() function. Right?
But the function returns a very long, long list object stretching across one line in the console.

No good. I want it broken up into smaller pieces. Oh no! How do I do that? I'm cluless. My mind is a BLANK.

I go to sleep. "Idiot!", my subconscious replies upon waking up. Have you forgotten how to slice a list? Seems so. Amnesia has struck. It happens. Even to me. Luckily not a permanent condition.

Point is, we have to repeatedly go back to fundamentals (back to our roots) and refresh them or else we forget them. Even the most elementary ones.

Eventually, I got it going. But in the process realized I don't remember how to convert a list into a set of strings.  (See the G4G answer HERE) I don't remeber how the join() function works! (See the G4G answer HERE) I can't get the len() function to work inside my OOP method! (See the Google answer HERE)


More importantly I'd flunk the interview exam for knowing anything about OOP (HERE)

Rinse and Repeat.
Got to get back to the fundamantals.
Too full of myself.


Wrote my own r_pad() right justification function
Used map() to apply r_pad to each element of dir(self) list:

def r_pad(self, txt = ' ', size = 20): # see gQAB ::: "python determine length of a string while inside an OOP method"
pad_on_int = size - len(txt)
pad_on = " " * pad_on_int
padded = txt + pad_on
return padded

def show_dir(self, begin, next):
show_txt = " ".join(list(map(self.r_pad,dir(self)[begin:next])))
return show_txt



Comments

Popular posts from this blog

Links for Python Noobs

The Learn HOW to Learn Page

Welcome to Circular Import Hell