Perl: How do I do this?
Sorry people.. it is python.... not perl... is there a way to change the title?
Hi, I am new to perl language. I have a string. I want to get the PBot id number (1D) It is a hex number. I want to convert it to a decimal number and print it. Thank you, Code:
#!/usr/bin/python |
1) That looks like you're using Python to me
2) What's your attempt so far? 3) Look into regular expressions, pattern matching is probably more reliable than going for a specific static character/substring position. |
Quote:
|
Sorry people... It is python...
And the data is all same pattern data = "iwconfig ath0 essid PBot_18 channel 4950M" data = "iwconfig ath0 essid PBot_19 channel 4955M" data = "iwconfig ath0 essid PBot_1A channel 4960M" data = "iwconfig ath0 essid PBot_1B channel 4965M" data = "iwconfig ath0 essid PBot_23 channel 4940M" only PBot id number and channel are changing. I was looking into parse function, but it doesn't seem to work.. |
Which parse function? Post your code.
http://docs.python.org/py3k/library/re.html An example RE pattern for this: "iwconfig ath0 essid PBot_([1-9]{1}[1-9A-F]{1}) channel 49([0-9]{2})M" Produces 2 groups, both should be 2 characters in size. It's a start, some assumptions made, you can say if it's too broad/precise. Or just use slices http://docs.python.org/py3k/tutorial...n.html#strings data[25:27] and data[39:41], my indices might be out. |
Thanks Proud, the following code works!!
Code:
PBot_id = int(data[25:27], 16) |
All times are GMT -5. The time now is 06:45 PM. |