convert hex to decimal

C

challman

I'm executing the following:

def run(self):
# get ntp_column
pop = os.popen("snmpget -v 1 -c SLI398uwiE " + self.host + "
1.3.6.1.4.1.9.9.168.1.1.9.0\n")
popS = string.join(pop.readlines())
if "Unknown host" in popS:
output.write(self.host + " - unknow host.\n")
return
elif "Error in packet" in popS:
output.write(self.host + " - error in SNMP query.\n")
return
popS = popS.split('INTEGER: ')
clmn = str(popS[1].replace('\n', ''))
time.sleep(1)
# get ntpRootDelay
pop = os.popen("snmpget -v 1 -c readonly " + self.host + "
1.3.6.1.4.1.9.9.168.1.2.1.1.13." + clmn + "\n")
popS = string.join(pop.readlines())
if "Unknown host" in popS:
output.write(self.host + " - unknow host.\n")
return
elif "Error in packet" in popS:
output.write(self.host + " - error in SNMP query.\n")
return
popS = popS.split('Hex-STRING: ')
delay = popS[1].replace('\n', '')
delay = delay.replace(' ', '')

The output from the second popen is:

SNMPv2-SMI::enterprises.9.9.168.1.2.1.1.13.51858 = Hex-STRING: 00 00 00
26


I need to get the Hex-STRING into the following format: 0.0038.. I know
how to covert 26 to 38 but I haven't figured out how to pad it or place
the decimal point between the while number and the decimal.
 
P

Peter Maas

popS = string.join(pop.readlines())

Why not popS = pop.read()?
The output from the second popen is:

SNMPv2-SMI::enterprises.9.9.168.1.2.1.1.13.51858 = Hex-STRING: 00 00 00
26


I need to get the Hex-STRING into the following format: 0.0038.. I know
how to covert 26 to 38 but I haven't figured out how to pad it or place

Have look at ljust/rjust(width[, fillchar])
the decimal point between the while number and the decimal.

What's a while number?

Peter Maas, Aachen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top