RSS Feed


Comments RSS


Lately, I have heard several political candidates and commentators use the phrat a se “man up!”  Of course, this is not a new phase.  On the milder side, it means “get a grip”, while on the meaner side it means “grow a pair!” (I do not think an explanation is necessary…).   Today I ran across a website that is devoted to helping men to MAN UP!    I think you will enjoy it.  Many men need it.  Many women just might understand men a bit better after reading it.    The Art of Manliness

Python – being exceptional!

One of the key features of Python that often gets overlooked is its ability to deal with exceptions, which is any time a piece of program code could throw a system or runtime error and end abnormally.

The construction that Python provides to handle these situations is the try:/except: combination. The idea is that you have a piece of code that has a high likelihood of creating an error, also call “throwing an exception”. This portion of the code is put in the try: section. If the first piece of code executes normally, without error, the program continues normally. If it traps an exception, then the code in the except: section is executed. In this way, the program continues one way or another in the event of the expected error. This finds its use very often in file handling code where a file open request might fail.

Here is an example. Also, this demonstrates how to do some work in SQLite3 (might as well get two useful examples for the price of one, right?). In this case it is not a file error that is being watched for by the exception handling code, but instead a runtime error that would be created by trying to add a table to a database if the table already exists.

#Create anSQLite3 database.
connection = sqlite3.connect(‘parts.db’) #If the database does not already exist, it is created.
cursor = connection.cursor() #Create an instance of the database cursor.

#Try to create the table “myparts” in the parts.db database. If the table already exists, print an appropriate error message rather than crashing the program with an error and continue with the program.

cursor.execute(‘CREATE TABLE myparts(id INTEGER PRIMARY KEY, part_number VARCHAR(16), part_desc VARCHAR(50), part_type VARCHAR(12))’)
print(“DB already exists”)

HOWTO-Build a searchable dictionary from a .csv using Python

##Building a searchable dictionary from a .csv using Python
##by Bill Allen    10/20/2010

##Sample contents of test.csv, the first row was a header row in the file
##    Material,Material description,Dv,Matl Group

>>> import csv                        #import the csv module for handling of Comma Separated Value files
>>> g = {}                          #create an empty dictionary
>>> reader = csv.reader(open(“test.csv”, ‘r’))         #for the csv module, this reader object is much like a database cursor object
>>> reader_list = list(reader)                    #create a usable list from the reader object (the entire test.csv file contents)

#As read in from the file, each list entry is a list of 4 strings.
#Each could be thought of as a record consisting of:
#[part_number, description, product_line, product_type]
>>> print(reader_list[1])
>>> print(reader_list[2])

#Now we start building our dictionary.
#In this example, we want the part_number, description, and product_type.
#For each entry in the dictionary the part_number is the key value ((THINK HASH TABLES!)).
#The description and the product_type will be stored under each key as a tuple so each part
#of the dictionary entry is still independently accessible.
>>> g[reader_list[1][0]] = (reader_list[1][1], reader_list[1][3])
>>> g[reader_list[2][0]] = (reader_list[2][1], reader_list[2][3])

#Here is our resulting dictionary.
>>> print(g)

#Print out individual dictionary entries by part_number.
>>> print(g[‘256213’])
>>> print(g[‘256214’])

#Print out description and product_type information independently by part_number.
#All the data that was stored in the dictionary is fully accessible!
>>> print(g[‘256214’][0])
>>> print(g[‘256214’][1])

#Now we can test search the dictionary for part_numbers.
#Just some simple Boolean tests here to demonstrate.
>>> ‘256214’ in g
>>> ‘256213’ in g
>>> ‘256216’ in g

#Now for a sample program.
#We will build the dictionary and then print out the first 9 entries.

import csv
parts_dict = {}
reader = csv.reader(open(“test.csv”, ‘r’))
reader_list = list(reader)

#Build the dictionary.
for i in range(1,len(reader_list)):
     parts_dict[reader_list[i][0]] = (reader_list[i][1], reader_list[1][3])

#Print out the first 9 entries with little bit of formatting thrown in.
for j in range(1,10):
     print(“key>”,reader_list[j][0],” – data>”,parts_dict[str(reader_list[j][0])], sep=”)

key>256213 – data>(‘IRON KIT STEWART & STEVENSON TRIPLEX’, ‘Z-OTF989’)
key>256224 – data>(‘IRON KIT STEWART & STEVENSON QUINT PUMP’, ‘Z-OTF989’)
key>3100695 – data>(‘+A RING 2.00 LS20 BRS’, ‘Z-OTF989’)
key>3100720 – data>(‘LF020 LS20 UNIRAW BENT’, ‘Z-OTF989’)
key>3100784 – data>(‘JP060 OLPO SIR F .625 BALL’, ‘Z-OTF989’)
key>3100789 – data>(‘JP060 OLPO SIR M .625 BALL’, ‘Z-OTF989’)
key>3100791 – data>(‘JP100 OLPO SIR M .625 BALL’, ‘Z-OTF989’)
key>3100849 – data>(‘JP120 OLPO SIR F .625 BALL’, ‘Z-OTF989’)

Benoit Mandelbrot dies, aged 85

As regular readers of my blog will know, I have been a fan and enthusiast of the mathematically derived images know as Fractals for many years after having been first exposed to the concept in an issue of Scientific American in the Mathematical Recreations column. I began writing programs to generate these beautiful images and even today still tinker around with these. Benoit Mandelbrot, the man who started it all and for whom the iconic fractal image is named, has passed way at age 85. The impact of his work went far beyond just some pretty pictures.   He fundamentally added to our understanding of nature and brought order to what had always been thought to have been random chaos in complex systems such as meteorology and reaching even into the fields of economics and the social sciences. His work was the genesis of what we now know as Chaos Theory. The impact of the revelation that Benoit Mandelbrot brought to human understanding of the world around us and of complex systems has already been felt.  It will continue to be felt as we delve deeper and deeper into the exploration of nature.  We are now assured that there will always be more beauty to be found as the self-similar and endlessly complex world unfolds before us. To me, Benoit Mandelbrot opened a door to us into the beauty and complexity of nature and into the mind of nature’s Creator. He will be missed.

The Mandelbrot Set

It gets even worse for Microsoft

It gets even worse for Microsoft. As I mentioned in my previous blog entry, Linux is beginning to catch up with Microsoft Windows in the workplace. However it is not only Linux doing this. Windows file servers are now often replaced with NetApp filer appliances. Well, NetApp is not based on Windows and it makes one or more Windows servers go away. While the NetApp OS, Data ONTAP, it is not based on Linux, it is based on other members of the Unix family.

Linux is on the Rise for Business

This is good news for the Linux world.   As Linux becomes more adopted by business, its usage in other areas is also more likely. Linux is on the Rise for Business

MRI, not fun…

Today I had a VERY unpleasant experience.  I have never considered myself claustrophobic, but after having a MRI today I am really beginning to think I might be.  That was a very tight space and the sounds the MRI machine makes are terrible.  I was getting the MRI for a back problem and laying flat on my back is one of the positions that hurt me worst, so of course I had to lay in there that way and be perfectly still.  The space was so tight that I could not move very much even if I wanted to.   I became quite anxious and my blood sugar plummeted.  Generally, just a bad experience.  That was only 25 minutes in that infernal machine!  I now understand what a trapped animal feels like.   Yet, I got a reminder when I turned on the TV how much I should actually consider myself blessed.   They are preparing to rescue the trapped miners in Chile via a capsule only 21 one inches in diameter through a hole they drilled from the surface down to the location of the miners.  It will take a whole hour just to pull each one out and after so many days trapped underground.  Those are truly courageous men and all the people involved in the rescue are just awesome.   My hat is off to them all.   I feel like such a dope for letting that experience with the MRI machine get to me…

A Blessing

Tonight, while familiarizing myself with SQLite3, I did what I often do when learning a new item or subject, that is I looked into its history and background. I even sought to read the licensing for SQLite. I found that the code for this remarkable database system has been utterly released to the public domain. Instead of a copyright or license, it offers this blessing, which I find very touching and in turn offer it to the kind readers of my blog. This is one of those rare times that the geek realm and spirituality intersect.

May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.

Please, also read this interview with Dr. Richard Hipp, the author of the above blessing and inventor of SQLite.,-geek-of-the-week/