Why I like Python so much.

Why I like Python so much.

I wrote an article about how proud I am of the team I have at WSP, where I’m employed, and while I’m in the process of co-writing another article about the use of technology in the Co-Living/Co-Housing market sector I had this idea for a short article on a computer programming language named Python.

My use of technology to solve challenges at home helps me to stay innovative in my work. A look at how I’ve used hardware and software to fix common problems that bothered me with my home and how I learned to apply those same approaches at work. This methodology, regardless of the toolkit (in this case a Raspberry Pi and Python), leads to research, experimentation, re-iteration, and the never-ending search for improvements. This is what defines me as a consultant.


A Brief History

In a weird way, I think I can trace the fondness I developed for Python to my father, let me explain. 

Growing up we often did certain tasks ourselves, where other families may have hired someone or paid for the service. My Dad had a financial background (accounting, comptroller, etc.), I’ll describe him as cost conscious and leave it at that. I got accustomed to mowing the lawn, shoveling snow, etc. I do, however, think they were valuable lessons, I still cut my lawn, shovel snow, and recently painted the outside of my house (a 2-year project). 

After moving into our current house it would often bother me when we would turn on the central air-conditioning system to cool the house only to later learn that the outside air temperature was lower than the temperature we wanted inside the house! This was the same time the Raspberry PI was released. The raspberry Pi is an inexpensive single board computer with many input/output connections. So, I decided to use the Raspberry Pi to build my own BMS. In the commercial construction and engineering world a BMS is a Building Management System, it controls and manages the buildings operational systems (mechanical, electrical, plumbing, etc.), so in my case I called it a HMS; Home Management System.

No alt text provided for this image

I had light and temperature sensors in all my rooms, some water flow sensors strategically placed, I monitored interior and exterior (fence gate) door positions, outdoor air and ground temperature. I spent about 3 years building the hardware while at the same time learning Python. Channeling my father’s spirit of ingenuity, instead of buying sensors, I built my own, down to the component level, using mini perf boards, DB1820 one-wire temp sensors and photocells. The first version of software I wrote polled all the sensors and displayed the data in a GUI (graphical user interface). As the number of sensors grew, performance quickly degraded. My second version became nimbler, I wrote one program that recorded all the sensor data and stored it in a SQL database, another program read the data and would send me texts for critical conditions, pushed data to a website, and created graphs. Finally, another program was the dashboard and it could run on any computer; Mac, Intel, Linux, Raspberry PI, etc. It would display the data in a simple floorplan with graphs showing trends. HMS 2.0 has been down for a little while now while I continue to make other improvements, it’s a never-ending process of adjustments, new technology, revelations and new ideas… 

No alt text provided for this image

In my professional life, I’m not a professional programmer, instead I manage a brilliant group of individuals who design building technology systems, however, I still use Python whenever I want to methodically automate or analyze something. Like my approach for using Python to solve technology problems in life I’ll do the same at work. For example: financial data in excel (using openpyxl Python library), a deadline dashboard on Google docs (using gspread library), Revit (using my favorite: pyRevit library). I call these libraries, but in Python code they are referred to as modules and I’ll touch on them a little later in this article.

The list

After using Python for several years now I put together this list of reasons why I think everyone should learn Python. To be fair I also included (in my opinion) the one major fault Python has.

No alt text provided for this image


1.      It’s in everything

OK, so maybe that’s not exactly what I meant. I was going to say it’s so widely supported – but that makes it sound like there’s so much help (tech support), maybe ‘It integrates with everything’ is a better way, by now you should understand what I mean…


2.      Elegant and readable.

The Python language may be classified as readable because of its prominent use of whitespaces and the English language.  Unlike other programming language, sometimes called the curly bracket languages (C, C++, Java, Perl), Python code is much easier to read and understand. Why is that important? I may often go several months without writing/looking at code and when I do find a reason to use Python again I will often re-use code. Reading code that is, for the most part, plain English, leads to less bugs, lets me remember the commands faster and allows for easier re-use of code.

3.      Modules, modules, modules

Again, because Python is so popular there are modules for nearly everything. In simple terms a module is code you can import to handle some of the heavy lifting for more complex programming task. Why is this import? A simple example, importing the “FTPLIB” module in the beginning of my program I can later in my code write a single line to upload a file to an FTP site, it’s that simple.


4.      Cross platform

I can write one program that works on multiple types computers/operating systems; Apple, Windows, LINUX, etc. It can even have a GUI (graphical user interface).


5.      Interpreted Language, no compiling runtimes.

Python is called an interpreted language because it is compiled when it is run, as compared to the more complex programming languages that are compiled before they are run. This makes using Python a little simpler to use, it’s one less step.


6.      Free and most likely already on your computer

Most computers already have Python loaded on them, if not Python is free. Windows based computers do not come with Python pre-installed, but it available in the Windows store, however, to check if your Windows computer already has Python, press the Windows key and “R”, in the (run) dialog box that opens type Python. If Python is installed a window will open telling you the version, in that window type “exit()” to quit and close the program.


7.      Most popular language now, endless resources on internet.

Maybe a popularity contest isn’t the best reason to choose anything, but consider why it’s the most popular programming language, and think about reasons 1-6. Also, If you look at pypi.org, a website that stores and indexes Python packages there are nearly 400,000 users and more than 1.5 million packages. Google any error message and there a wealth of search results pointing to other users experiencing the same message. I’ve very rarely had to post a problem I needed help with.

It’s one Fault:

This isn’t a huge issue, just something that’s nags at me. There are two popular versions of Python; version 2.7 and 3.x (3.8 now). Version 2.7 will no longer be supported by the Python Organizations after January 1, 2020, meaning there won’t be updates (including security updates) after that date, although there’s nothing stopping people from using 2.7 and it’s still very popular. Python 3 is not backwards compatible with python 2.7. There are a few differences between these two versions that will prevent code written for Python version 2.7 from running in 3.x. It hasn’t been a problem for me, everything I’ve written is in 2.7 and I’ve had no issues. It’s just an annoyance.

In Conclusion

Maybe one of these seven reasons by itself is not enough to convince you to learn Python but when you look at all of them together its very compelling. Several years ago, and before there was a way to use Python with Revit I tried very hard to learn C. I spent a month watching training videos during my commute, cleaned up my hard drive for the albeit free but massive Microsoft Visual Studio. In the end, it still looked like someone dumped a cup of alphabet soup on my screen and I gave up. With my other responsibilities, the time it would take to learn C wasn’t (in my opinion) worth the time. I still maintain, unless you are a professional programmer and writing code for likes of operating systems and other complex software, Python is all you need.

So, where do you start? For me it was LPTHW (Learn Python the Hard Way), a while back it was a free E-book, but now I understand much of it is behind paywall. Automate the Boring stuff is another popular free E-book. Codeacademy.com is a free online training site with Python courses. Stackoverflow.com is an online community for sharing programming knowledge. Of course, there’s always Google too.Are you planning your own Home Management System (HMS)? If so, send me a note. Let’s think together. 

要查看或添加评论,请登录

Tim Lehotsky的更多文章

  • An AI Coding experiment and the 10 things I learned

    An AI Coding experiment and the 10 things I learned

    With the enormous popularity of AI, there’s no denying it is everywhere—whether I’m looking, reading, watching, or…

    1 条评论
  • RIP Boat Brain

    RIP Boat Brain

    For the last couple of years, maybe once a year, I would write a post about the wooden boat I was building. I finished…

    6 条评论
  • Part I - Why I chose the ESP8266 as my wireless micro controller and how I use MQTT with it.

    Part I - Why I chose the ESP8266 as my wireless micro controller and how I use MQTT with it.

    Most of my articles discuss a specific topic. This one will be a little different, Part 1 will explore why the ESP8266…

  • How Cloud Services Have Changed Application Development

    How Cloud Services Have Changed Application Development

    I am often asked, What is the cloud? In response, I point to Dropbox, a service that allows users to store files both…

    2 条评论
  • IBM Watson IoT, Python3 and JSON

    IBM Watson IoT, Python3 and JSON

    To store, aggregate, and analyze building data is an enormous task and often this means the storage and compute…

    4 条评论
  • Exploring New Experiences in Mediated Communal Living Models

    Exploring New Experiences in Mediated Communal Living Models

    Communal living has a long history of failure. Frictions around lifestyles, paying the bills, and basic housekeeping…

    1 条评论
  • Getting Smarter Together

    Getting Smarter Together

    This past spring two of my daughters had milestone graduation ceremonies; one from eighth grade and the other from high…

    6 条评论

社区洞察

其他会员也浏览了