I'm given a hexadecimal number in string form with a leading
"0x" that may contain 1-8 digits, but I need to pad the number with zeros so that it always has 8 digits (10 characters including the
"0x12345678"should be unchanged.
I am guaranteed to never see more than 8 digits, so this case does not need to be handled.
Right now, I have this coded as:
padded = '0x' + '0' * (10 - len(mystring)) + mystring[2:]
It works, but feels ugly and unpythonic. Any suggestions for a cleaner method?