def intfloatsplit(x):
    i = int(x)
f = x - i
return i, f

def prettydegrees(d):
    degrees, rest = intfloatsplit(d)
minutes, rest = intfloatsplit(60 * rest)
seconds = round(60 * rest)
return "{degrees}\xc2\xb0 {minutes}' {seconds}''".format(**locals())
Pretty-printing physical quantities with automatic scaling of SI prefixes