Python

NULLs in the Windows Registry

in tech    3 min. read

December 1, 2017

I ran into an interesting issue with my Windows development machine when trying to test a Flask web app. This was due to werkzeug running the simple web server for flask that is created when you us app.run(). The error had me confused at first, as it has nothing to do with what I was changing at the time: TypeError: OpenKey() argument 2 must be str without null characters or None, not str I tracked back through the stack to see that werkzeug is looking at the Windows Registry.

Continue reading

RPi Startup IP and Web Display

in tech    4 min. read

October 28, 2017

I’m using a Raspberry Pi 3 as the CPU in custom burn-in carts for cycling our Android tablets. It is hard to beat the 7” touch display using a Flask front end for quick development. The carts often have power connected and disconnected when moved around. We are also using a network inside of the carts for talking with tablets under test and need to bring this up each time we move carts and cycle power.

Continue reading

Python to Rust: Enum

in tech    10 min. read

August 25, 2017

Enums are new with Python 3.4 and PEP 435, but have been backported. At first, I saw more trouble than benefit from Python Enums. They are typically used for type safety, and this isn’t really enforceable in Python. But, since they are a class, you can add additional functionality to them. This gives them more usefulness than I previously thought. It isn’t easy to store data with them in most languages.

Continue reading

Python to Rust: Types

in tech    13 min. read

August 24, 2017

Comparing Python's Dynamic and Strong-ish type system with Rust's static and very strong type system. Covering the scalar and a few of the complex types.

Read Blog Post

Python to Rust: PIP to Cargo

in tech    8 min. read

August 23, 2017

This post discusses Cargo, the packaging tool for Rust. I compare it with Pip and explain how dependencies are referenced in Rust. I explain how to create new Rust projects with cargo and to build and run them.

Read Blog Post

Python to Rust: Beginning

in tech    9 min. read

August 22, 2017

As a Python programmer, I discuss wanting to learn a new language and my choice of Rust after looking at both Rust and Go as possibilities.

Read Blog Post

Python: Collections Library

in tech    8 min. read

July 10, 2017

One of the best ways to become efficient with Python is to really learn the standard libraries. However, do this with understanding that some are included for base functionality or compatibility, but have been superseded by better packages in PyPi. Requests over urllib2 is a great example of this. By being outside of Python, these packages can iterate faster and not be dependent on Python releases. Collections is not one that needed replacement.

Continue reading

Python: Dunder name

in tech    8 min. read

June 24, 2017

You may have seen if __name__ == '__main__': at the bottom of a script. Why is this there and what does it mean? First, a python file is a module. They can be combined into a directory module and this is what is being done when you see an __init__.py file in the folder. We will get there in a little while, but first we will cover a little more than just __name__.

Continue reading

Python: Iterators and Generators

in tech    8 min. read

June 17, 2017

Iterators and Generators are two mechanisms for providing data to cycle through in Python. The difference is if the data is already in memory and we iterate along it, or if we are generating it as we go. The names actually make sense. These turn out to be very similar and just differ in execution. One is better if you already have a class. The other is a little simpler.

Continue reading

Python: Context Managers

in tech    6 min. read

June 10, 2017

Context managers were added to Python with PEP 343. This allows proper handling of resources without worrying about missing something in your try/finally code. If you are not opening files using a context manager, you are most likely doing it wrong. Looking at opening a file and what could go wrong, will show how context managers make programming both more robust and simpler. The operation can be broken into 3 sections of code.

Continue reading