Unable to paint texture
That example tutorial runs and returns an error if you haven't saved the example image in the tutorial to your home folder. 

Texture paint is easy enough without python code being necessary, but this seems to be over-complicating what would be normal per face material and image texture assignment. The example tutorial provides no result that is of benefit other than to understand how the code works - but I may be biased toward using a paint or bake option instead.