Wednesday, 15 January 2014

string - Python Extract variable data from lines -


I need to extract several pieces from an HTML file in the Axle Sheet. I have pulled the data, now let me find the lines Here is an example:

  "501.92 seconds: iPhone 5s_DownStream HTTP_TCP_Downlink_1: ILOAD = ** 12.000 ** Mbps Oding = ** 4.999 ** Mbps Freight = 4.980 Mbps L4 Goodput = 4.788 Mbps Packet loss = 0.38 SLA result = ** failed ** & lt; font color = white & gt; " 

I bold those items Confirms that require I figure. Because these values ​​make every change in every file and they should be saved in the variable name, I really do not know where to start

OK, here's the answer to a hack ... it does not look beautiful, but if your string pattern remains the same, you should be able to get results.

  string = "501.92secs: iPhone 5s_DownStream HTTP_TCP_Downlink_1: ILOAD = ** 12.000 ** Mbps Oding = ** 4.999 ** Mbps Freight = 4.980 Mbps L4 Goodput = 4.788 Mbps Packet Loss = 0.38 SLA results = ** fail ** & lt; font color = white & gt; "import re-def getnumbers (string, pattern): Results for pattern = [], number in pattern.items (): match = re.search (Pattern, string) valuestart = match.span () [1] results.append ([Pattern, (string [valuestart + 3: valuestart + number + 3]) Return result # If you need to get more value , Then add them to the dictionary in logic. # The number next to each pattern represents the expected size of the result. Print (meet (string, {"ILOAD =": 7, "OLOAD =": 7, "result =": 4})) # [['result' = ',' failed '], [' offset = ',' ' 4.999 ** '], [' ILOAD = ',' 12000 * ']]  

1 comment:

  1. I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers
    list to string python

    ReplyDelete