The other day I had an awesome mentoring session with a beginner Pythonista, amazing what 30 min of screen sharing can do. Read on to learn more …
There was a clear goal: get data from an API so I taught the following:
-
First make a virtual environment, activate it and
pip install requests
. -
Open a
script.py
, import the library and define the API endpoint. -
Use an f-string to embed variables into the API endpoint.
-
Use
requests.get
with the endpoint URL and its kwargs to send HTTP Headers / secret auth token (more below). -
How to load in the token from the environment (
os.getenv
) to hide it from the source (we added it tovenv/bin/activate
). -
Use pdb to inspect the response (one of my favorites).
-
How to read code of an external library.
-
And more …
Feeling as excited as we were hacking this together?
Well, this was only the technical part!
What was more interesting was teaching the PROCESS:
-
He saw me use the tools of a professional environment: venv, pip, requests, coding in vim, etc.
-
He got an idea how I approached this problem, my thought process. This is golden when you get started.
-
I did not write a function. I just got something to work first (drop perfectionism).
-
We hit a
401
which meant we were not doing authentication right so we advanced from there (quickly iterate). -
Similarly we hardcoded the token in the code to get it working, later we pulled it into an env variable.
-
Sending HTTP headers with requests was not something I knew from memory so I had to Google it and landed on Stackoverflow. As a developer you keep learning and googling, you just come better at how to look. He made me aware of this.
-
It was nice to teach the bare minimum but leave enough up to a challenge for him. Good mentoring is to give mentees just enough to get going, but they have to do the work. You just guide them.
-
Although he was a beginner, he saw how I used
pdb
to inspect variables, a powerful skill. -
I typed help in pdb (duh), then in the REPL, but ended up going to requests’ source code which he really enjoyed. I told him that “if there was one thing I would have done earlier as a becoming programmer …”.
-
I hardcoded a variable and added a
TODO
to make it a command line arg later.
Invaluable stuff. Coaching has a clear win/win here:
-
Mentees win because they can focus their efforts.
-
Mentors win by better understanding the concepts at hand, gaining tactics for effective knowledge transfer, and learning about common knowledge gaps and roadblocks.
Cliche or not, but the best way to learn is to teach.
Have you had a similar experience, be it as a mentee or a mentor? Share it in the comments below …
Keep Calm and Code in Python!
— Bob
This is how we coach our clients every day. There are no shortcuts to becoming a proficient Pythonista, but you can definitely get major gains if guided into the right direction and applying the 80/20 that will make you a great developer. Book us in for a strategy session and let’s talk about your career and how we can help you.