Create an __init__.py file in each directory that will be in the tree of your import. For example, if you have the following directory structure… /opt/software/com/yourcompany/yourdivision/yourfile.py …you would issue the following commands: export PYTHONPATH=$PYTHONPATH:/opt/software touch /opt/software/com/__init__.py touch /opt/software/com/yourcompany/__init__.py touch /opt/software/com/yourcompany/yourdivision/__init__.py…
Category: Python
Interesting way to get domain associated with Amazon IP
While looking for timeouts in splunk for an unrelated reason… I noticed the Amazon IP’s above. We normally don’t know the service they represent. I connected to the IP in my browser on port 443, and noticed that of course…
Splunk query to group URI request by first three IP address octets
We needed this to understand the source of a large influx of requests for a given URI pattern. import splunklib.client as client import splunklib.results as results service = client.connect(host=”*******”,port=”8089″,username=”showard”,password=”************”) job = “”” search host=\”cmhlpecomweb*\” sourcetype=access_combined karlie-kloss | eval temp=split(_raw,\”\t\”) |…
SQL elapsed time over a small specific time window
This is a great quick script to identify those statements taking the most time over a small time window. It’s a good “911” type script. This will print those statements that have a total elapsed execution time of the percentage…
Simple network test with client and server
This simple network trace shows the essential elements of a network interaction between a client and a server. For our test, we use the following for the client… import sys, socket, time remote_ip = socket.gethostbyname(socket.gethostname()) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #s.setsockopt(socket.IPPROTO_TCP,…
Loading compressed data into MySQL in batches from python
We used what is below to load 12 million rows into a laptop MySQL database in 48 minutes. I’m sure it can be improved, but we were initially OK with this result. import gzip, os, sys, string, mysql.connector fd =…
Birthday paradox in python
I love things like this. Earlier, we produced a working example of the Monte Hall problem. In this post, we show something similar for the birthday paradox… c:\Python27>type c:\Users\showard\bday.py from random import randint cnt = 0 for k in range(2000):…
Python, cookies, and session management
While working with an external vendor, we had a need to understand how to manage HTTP session cookies with python. This is simply how we did it… import urllib, urllib2, cookielib, re cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) home =…
Determine the number of active sessions from the JBOSS access log
While planning for holiday shopper traffic, we realized that we did not record the number of active sessions at any given time during holiday 2013. To come up with something that would get us close, we wrote what is below…
Finding windows OS files modified in time range with python
We had a need to search some text files in Windows modified during a certain time range with a given piece of text. This is a network drive that is not indexed, so we couldn’t quickly rely on a windows…