[NTLUG:Discuss] Fwd: [DFWUUG:Members] Python Programmers Sought for Hire

Carl Haddick sysmail at glade.net
Mon Jul 27 18:58:52 CDT 2009


On Mon, Jul 27, 2009 at 11:34:08AM -0500, Robert Pearson wrote:
> Carl, FYI...  I liked your NTLUG Python script. I am moving from
> Bourne, Cshell, Korn, Tcl/Tk, Bash to Python - slowly. Not Python's
> fault.
> 
> ---------- Forwarded message ----------
> From: Jeff Rush <jeff at taupro.com>
> Date: Jul 7, 2009 4:17 AM
> Subject: [DFWUUG:Members] Python Programmers Sought for Hire
> To: members at dfwuug.org, "General Announcement List (Low-Traffic)"
> <notify at dfwuug.org>, dfwpython <dfwpython at dfwpython.org>
> 
> 
> Hi, it's me again.  I've been contacted by two local companies that are
>  looking to hire Python programmers, contract or perhaps salaried.  I
>  know that several of our members are out of work.
> 

Thanks for the forward, and your kind words.  I hope I'm not posting too
much as a lurker - apologies in advance if I am, I just get a hoot out
of Python.  It's just close enough to a real language to get real work
done without my hurting myself too frequently.

I like objects partly because they are easy to set on the shelf for
later re-use, and also because they form easily testable units of code.

Anyway, I got to thinking about the times I've messed with joined text
files in Python so I took a few minutes this evening and made a class
(object).  Basically, just put the functions under a line 'class
<classname>:', a little editing, add a few 'self' references for
instance variables, and I have a new Python gizmo I can use without
looking at its innards.

I'm not sure if anyone is interested in a half-baked Python idea, but
here goes.

I figured in the future I would want to declare a root level file with
regular expressions to identify a key and a data field.

Then, I wanted to tell it to add a child file, named as being in a path.
That way there could be more than one path down a tree, subdirectory
style.

So, given the pairings phone#/ip, ip/mac, mac/switch port, what if you
also wanted ip address/city lookups?  There's verbage for regexes and
other stuff, but two fetches and a print in a for loop gets the data for
both paths.  In abbreviated form, the object 'stuff' is my tree of text
files:

<snip...>

for k in stuff.dataset:
    pathdata=stuff.fetchval(('root','macaddr','portnum'),k)
    citydata=stuff.fetchval(('root','city'),k)
    print 'Phone %s, IP %s, mac addr %s, port %s, city %s'%
      (pathdata[0],pathdata[1],pathdata[2],pathdata[3],citydata[2])

Output looks like:

Phone (666) 234-5678, IP 4.5.6.7, mac addr 22:33:44:55:66:77, port p2, city Philly
Phone (777) 345-6789, IP 7.8.9.10, mac addr 33:44:55:66:77:88, port p3, city Dallas
Phone (555) 123-4567, IP 1.2.3.4, mac addr 11:22:33:44:55:66, port p1, city Austin

Just a little meandering at the end of the day.  If anyone wants the
class it's very 'off the cuff' but it works.  It's about 70 lines and
could use more error checking or the capacity to save duplicate keys.
It's on my rather useless web site,
http://www.windwardshore.net/filejoin.html .  Use the full url, there is
no link on the default page to anything.  For the full version of the
example, http://www.windwardshore.net/filejoinexample.html .

Pardon my poor commenting and the style errors that are bound to be
there - supper's waiting, so quickly must I type! :-)

I suspect I may use my file joiner in the future for quick and dirty
things.  I have an IP class that I have used on a number of occasions.
With it I can do things like 'for ip in IPAddr('192.168.0.0/22'): blah,
blah' to spin through all the addresses in a subnet.  Funny how simple
things can help later on.

Regards,

Carl



More information about the Discuss mailing list