I'm writing a python (2.7.6) script that pulls JSON data from a webserver and publishes it elsewhere. I only want to publish those JSON values that are numeric, e.g. no sub-objects or strings. It's very likely that the numeric values will exceed the size of int
(in the C sense of size). My current code looks like this:
for metric, currentValue in json.items()
if type(currentValue) is int:
oldValue = previous.get(metric)
if oldValue is None:
oldValue = 0
delta = currentValue - oldValue
publish(metric, delta)
previous[metric] = currentValue
My concern is the type check. If Python decides that int
is no longer appropriate and uses long
instead it means some metrics will not get published. And what to do if long
gets exceeded?
What I really want is a way to check that currentValue
is numeric.
There is isdigit
but that doesn't work for negatives or floats.