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.
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.
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.
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.
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.
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.