Bug fix and improvement for the Metadata.py example. (rebased onto dev_5_0)



This is the same as gh-2146 but rebased onto dev_5_0.

----