Getting Started With Python (Part 1)

By Travis K. Jansen | Team Lead, Software Development

This is the first in a series of blog posts chronicling my journey into the world of programming with Python.

Why Python?

Being a baseball fanatic, I was first introduced to Python in my hunt for a good source of advanced baseball statistics when I stumbled upon a project called Baseball on a Stick. This project’s goal is to utilize Python to pull data from the MLB website and aggregate it into a database for consumption. To set it up, the process can get complicated and requires the user to install and configure Python. I got it up and running, but ran into some issues that I wanted to tweak or errors in the code that needed updating. Since it was written in Python, my next steps were clear and I committed to learning Python as my next programming language. The ultimate goal is to learn the language to better myself technically. However, as I often use my technical skills to enhance my hobbies or automate otherwise manual tasks, I am also looking forward to having Python as another weapon in my arsenal.

Where The Hell Are My Curly Braces?

Ever since the late 90s when I began my foray into writing code, all I’ve ever known were curly braces, save for a brief stint with ASP, and a short, traumatic time with VB.NET. In college, my advanced programming courses were in C++. My client/server courses focused on Java. My first real love of writing code was born out of some early projects using PHP, which I still love to this day. Let’s also not forget JavaScript. The point is, all of these languages share a similar syntax and are varied more by their framework or platform than they are the reserved words typed into the IDE.

The following is a trivial comparison of a foreach looping construct for a few different languages:

// C#
@foreach (var post in Model)


// PHP
foreach($model as $post)
  <div><?php echo $post['Title']?></div>
<?php } ?>

// Laravel (PHP Templating)
@foreach ($model as $post)

In Python, this translates to:

for post in model:
     print post.Title

The Good and the Bad!!!

Python syntax is incredibly expressive, and reads and writes almost like plain English. Aside from inherently supporting and encouraging clean, readable code, the language is extremely diverse.

Out of the box, Python’s standard library provides a lot of useful utilities for programmers to take advantage of. However, it’s not just a command-line tool that allows you to write complex programs that assist in manipulating your file system, parsing content from the web, and loads more. It’s also a very popular tool for writing web-based content especially when paired with Python web frameworks such as Django or the Micro Framework Flask. What’s more? Python is at the top of the list of languages for machine learning and is generally considered a rising star as utilization continues to increase both for development as well as data science.

In contrast, Python as a language is not perfect and there are some things that will take some getting used to. Using whitespace to define scope feels a bit off to me and borders on breaking a personal code-style rule I’ve set for myself for curly-brace-languages: explicitly define your scope! Speaking of scope, Python is a dynamically scoped language meaning that the scope of a variable depends on the execution context and where it’s being called from contrasted with a lexically scoped language where the scope is dependent upon where the variable is defined. It is also known to be slower than other languages because it has to sacrifice some speed in order to provide its flexibility. Performance is one of the aspects of this exploration I’m interested in learning more about as I dive deeper.

Python is an expressive script-friendly programming language with seemingly infinite utility that runs on all major operating systems. With that kind of offering, I can’t afford not to invest my time into becoming proficient at it, and I’m excited to finally dive in. Part 2 of this series will focus on diving deeper past “for loops” and “if statements” into classes and some more advanced Python offerings.

Written on July 11, 2017