python
xml.dom.minidom cant process namespaces
I’m trying to parse log4j messages coming from external applications for a little logviewer GUI. However, the popular xml parsers don’t seem to handle namespaces at all.
Super Simple C Style Python Struct
Making a basic C style python struct is a simple one liner. But why stop here? The least you could do is implement some built in class methods. Ok it’s a silly example, but implement some fun things and before you know it you’ll have a full blown class on your hands.
Binary Buffers and Python Arrays
Python arrays, ctypes string_buffers, binary data payload and other usages in messaging interfaces. Per-allocate your buffers for high performance. Binaries used for decoding on two ends of a messaging interface can convey a lot of information and is quite a bit more efficient than sending structures full of other larger things like more arrays, doubles, etc.
Check to see if a button is sensitive in pygtk
Here’s a short example of checking for a save button’s sensitivity before proceeding to quit the main loop. This is something you may use when a quit button is clicked but changes have been made to a document and you want to give the user one last chance to save before exiting your application.
Automate login with mechanize and cookielib
Mechanize is good for loading pages and automating forms. This code will work as long as there’s not some weird javascript creating stuff needed for login on the fly that can’t be hand crafted on your side.
Redirect stdout to a string in python
I wanted to reuse a piece of code that’s complicated with recursive calls to itself and the whole thing prints to standard output. Instead of modifying the code to write to a file object, I just adjusted my own code with an internal class to redirect stdout to a string while the recursive code is running.
Get the filename of the currently executing python script
As you would expect, there are several ways to do this. Using stack from the inspect module will give you the full path and filename of how it was executed. If you run from a relative path such as ./src/file then the stack item will contain just that part.