Companionway

Meeting challenges with success

Parsing ansi Code

A function to extract ansi code ...

Dealing with strings that contain ansi codes for colorizing can be a challenge especially if you need the actual display length of the embedded strings.


Taking advantage of *args and **kwargs

Taking Advantage of *args and **kwargs I consistently forget the option word I have included in a function and so I had to design a way to accept different keywords (option) names to trigger features with in a function. As an example, assigning a color to a box border is very easy by just adding something like this to a function’s arguments: def buildabox(msg, border_color="red"): """ docs go here to put a box around msg """ .

gtoolz

The python3 collection of tools called gtoolz has been released and can be downloaded from github or using:


Python's all() function

Python all() function Much of my coding efforts are directed towards analyzing financial data specifically targeting potential cash secured puts or covered calls. Recently, I had to refine some market overview displays. I needed a listing of the current market “gainers” and market “losers”. There is one site which I scrape using panda read_html function to grab a hadful of tables. My problem arises from two factors. One is there are no labels or titles to the tables and they can vary.

Quick N Dirty Python Debug Function

Pdb is a great debugger for python but I like to use my own simple debug functions. Here is a simple debug function for python which could definitely be improved:


Sometimes It Is The Obvious

This was one of those “problems” that nagged me for many hours until the obvious dawned on me. I wrote a python script to grab the temperature and humidity from a DHT22 sensor and then write the output with the proper syntax to send to my monitoring program [xymon]. The wrapper bash script ran every 5 minutes and used a redirection to write out a file ie:

*/5 * * * * /usr/local/bin/temphum.sh >/tmp/temphum.dat

The wrapper script grabs output and sends it to the server. Having this wrapper script lets me run the python script independently for testing or for curiosity.