Add to_python() method to ScalarValue class
Correct use of dict iterations

Also, use items() everywhere instead of iteritems(), for forward
compatibility with python 3.