Python

Example Program

 * 1) !/usr/local/bin/python

import sys import socket import string

a = ['Mary', 'had', 'a', 'little', 'lamb'] for i in range(len(a)): print i, a[i]

def blah(s="blah"): print s   return True
 * 1) Functions


 * break/continue for loop control.


 * String Methods: http://docs.python.org/lib/string-methods.html

Using kqueue and kevent
http://docs.python.org/library/select.html#kqueue-objects


 * 1) !/usr/local/bin/python

import select from select import kqueue, kevent import os import sys

filename = "foo.txt" fd = os.open(filename,os.O_RDONLY) kq = kqueue

build the changelist of filters event = [ kevent(fd, filter=select.KQ_FILTER_READ, flags=select.KQ_EV_ADD), kevent(fd, filter=select.KQ_FILTER_VNODE, flags=select.KQ_EV_ADD | select.KQ_EV_CLEAR,               fflags=select.KQ_NOTE_DELETE | select.KQ_NOTE_RENAME), kevent(1000,filter=select.KQ_FILTER_TIMER,               flags=select.KQ_EV_ADD | select.KQ_EV_CLEAR, data=1000) ] events = kq.control(event,0,0)
 * 1) load the filters,return 0 events, wait 0 seconds

while True: print "loop" # wait for an event, None means do not change the changelist r_events = kq.control(None,4) for event in r_events: print event for event in r_events: if event.fflags & select.KQ_NOTE_DELETE: print "file was deleted" elif event.fflags & select.KQ_NOTE_RENAME: print "file was renamed" # not needed since we set the select.EVENT_CLEAR above also event.flags = select.KQ_EV_CLEAR kq.control([event],0,0) elif event.ident == 1000: event.flags = select.KQ_EV_DISABLE kq.control([event],0,0)

kq.close os.close(fd)