First of all , you should use "WRITEDATA" other than "WRITEFUNCTION". The later is for self defined function. Besides , python 3 is recommended.