Can API hooking in python be OS agnostic?

Hooking is a way to get your own code to execute when another system is running, whether that other system is an OS, a GUI, or whatever. A somewhat silly example in Python:

def Process(records, per_record_hook=None):
    "adds all records to XYZ system"
    XYZ = []
    for record in records:
        if per_record_hook:
            per_record_hook(record)
        XYZ.append(record)

def print_record(record):
    "print a '.' for each record (primitive counter)"
    print '.'

and then later:

Process(records_from_somewhere, per_record_hook=print_record)

http://en.wikipedia.org/wiki/Hooking

I'm going to assume you're referring to this ^ kind of hooking? I'm completely unfamiliar with the term, but it seems like you're looking for a library that allows interactions with the operating system?

If so, try something like PyWin32 (google it) or follow some of the techniques found here: http://www.rohitab.com/discuss/topic/37018-api-hooking-in-python/

Again, it'd be more helpful if you could put it (the phrase hooking) into more...Python-esque terms, but I hope this helps?


In Python things like this is generally so trivial that it's hard to even provide examples. Hooks are generally callbacks, yes. Callbacks in python are simply done by passing functions around and calling them.