Python: A Long and Winding Road
I first encountered Python several years ago when working on Oracle Virtual Directory, part of the identity solution supporting a then new Oracle-based web portal. Oracle Virtual Directory, or OVD, was designed to abstract multiple identity stores, whether they were native identity stores (LDAP) or not (databases), and make them seem like a unified directory. One of the “killer” features was the ability to merge, manipulate and otherwise bend the data to the clients’ will. To achieve this, one of the main weapons in OVD’s arsenal was a built-in scripting language that was a subset of Jython, the Java implementation of Python.
The use of Python as a scripting language proved very powerful, and while unfortunately my code didn’t make it into production (due to the instability of OVD itself and not the code), it left an impression on me. I picked up Mark Lutz’s Learning Python, 3rd Edition from O’Reilly (now up to a respectable 5th edition), with every intention of getting to know this language better. Alas, life intervened, as it does, and I only ended up a handful of chapters in before other distractions took hold.
What’s Old is New Again
Around the tail-end of 2014 I was casting about for something new to learn, and came across Programming for Everybody (Python) from Charles “Dr. Chuck” Severance on Coursera. The course was very beginner, non-technical-background oriented, because for Everybody, but I don’t code often in my day job and wanted to ease back in any way. I really enjoyed the course and ended up enrolling in the Python for Everybody Specialization. It is a series of courses introducing you to Python, data structures, access web data (lots of JSON), and databases via SQLite. It culminates in a Capstone project where you have to combine what you’ve learned into a cohesive whatnot.
What did I come up with? A little program I called Get Sirius, which builds Spotify playlists based on now playing information on the SirusXM website. The now playing information is grabbed from an associated JSON file on the SiriusXM website, the song checked against a local SQLite database to see if it’s a duplicate, and if not it’s logged in SQLite and then fired off as a web request to an IFTTT Maker Channel that turns around and adds the song to a Spotify playlist.
In less than 100 lines of code. Including white space and comments. Yeah. I was hooked all over again.
What’s the Appeal?
In a line:
print "Hello World!"
What if that line, or lines, comes from a text file?
for line in open('file.txt'):
Look how simple that is. How straight forward. A text file is opened and iterated through line-by-line, printing the contents out to the screen. In two lines of code. Two, easily read and understood, lines of code.
Because white space, especially indentation, must be used to end up with a usable program, Python code is actually easy to read. No tracking down curly braces or semicolons. For maintainability, or even starting out learning how various Python programs work, this is invaluable. Python has, effectively, embedded a culture of predictable communication into its specification. Powerful stuff.
Not to mention the abundant Python ecosystem, where there’s a module for practically everything. This let’s you focus on the core of what you’re trying to do, minimizing time spent coding and maximizing time spent Making Things Happen™.
The Road to ‘Hello World!’ is Paved With Good Intentions
I want to learn more about Python and what I can do with it. I’ve picked up a few self-paced online courses which aim to help you learn by doing. The fantastic Talk Python to Me podcast acts as my weekly Pythonic anchor whether I’ve been able to get any coding time in or not. And I’ve got my eyes firmly fixed on VMware vSphere. Be wary, vSphere, you will be tamed with Python.
Watch this space.
Featured image photo by yukop