def ishex(x): if x.startswith("0x") or x.startswith("0X"): x = x[2:] return all([c in string.hexdigits for c in x])