Thursday 15 January 2015

How do I set where a string starts and ends in python? -



How do I set where a string starts and ends in python? -

i working on project work, , work need capture info on serial port, set string form, , 2 key words in string. 2 words i'm looking "pass" , "2x400mhz".

at work have automated ram tester , automate sorting process ram passes using arduino. in order need monitor info comes out of ram tester via serial port , speed of ram beingness tested, , results of test (pass or fail). 1 time create string necessary info have python write arduino on serial , arduino take care of sorting.

the reason stuck, , makes hard info comes on serial port varies in length according if ram passes or fails instantly, halfway, or near end of test. test around 52 seconds 2gb module , 32 seconds 1gb module. module testing info comes on serial line name of test beingness run , timer counts second, when test on (failed or passed) of info on module's spd chip dumped on serial line along word "pass" or "fail". timer counter making amount of info per test different depending on fails why want create string of spd info since contains info has significance me.

i have used serial monitoring programme capture sample show info working with.the spd info interested in near bottom, rest of info above timer. info near bottom same besides spd info (speed, configuration, serial number). hoping there way have python utilize 1 word show before , after spd info start , stop creating string, way string spd info , exclude counter data.

..waiting handler start ....Åþ....[ esc. ]Åþe.Åþe.Åþe.Åþ.*..l001: wk_addr [00:00]Åþ....[cancel]Åþa'Åþ.*..l001: wk_data [00:00]Åþ....[cancel]Åþa'Åþ.*..l001: mats [00:01]Åþ....[cancel]Åþa'Åþ...![00:02]Åþ...![00:02]Åþ...![00:03]Åþ...![00:03]Åþ...![00:03]Åþ...![00:04]Åþ...![00:05]Åþ...![00:05]Åþ...![00:06]Åþ...![00:06]Åþ...![00:07]Åþ...![00:07]Åþ...![00:08]Åþ...![00:09]Åþ...![00:09]Åþ...![00:10]Åþ.*..l001: mar_x [00:10]Åþ....[cancel]Åþa'Åþ...![00:11]Åþ...![00:11]Åþ...![00:12]Åþ...![00:12]Åþ...![00:12]Åþ...![00:13]Åþ...![00:14]Åþ...![00:14]Åþ...![00:15]Åþ...![00:15]Åþ...![00:16]Åþ...![00:16]Åþ...![00:17]Åþ...![00:18]Åþ...![00:18]Åþ...![00:19]Åþ...![00:19]Åþ...![00:20]Åþ...![00:20]Åþ...![00:21]Åþ.*..l001: mar_c [00:21]Åþ....[cancel]Åþa'Åþ...![00:22]Åþ...![00:22]Åþ...![00:23]Åþ...![00:23]Åþ...![00:24]Åþ...![00:24]Åþ...![00:25]Åþ...![00:25]Åþ...![00:26]Åþ...![00:26]Åþ...![00:27]Åþ...![00:28]Åþ...![00:28]Åþ...![00:29]Åþ...![00:29]Åþ...![00:30]Åþ...![00:31]Åþ...![00:31]Åþ...![00:32]Åþ...![00:32]Åþ...![00:32]Åþ...![00:33]Åþ...![00:34]Åþ...![00:34]Åþ...![00:35]Åþ...![00:35]Åþ...![00:36]Åþ...![00:37]Åþ...![00:37]Åþ...![00:37]Åþ...![00:38]Åþ...![00:39]Åþ.*..l001: mar_y [00:39]Åþ....[cancel]Åþa'Åþ...![00:39]Åþ...![00:40]Åþ...![00:40]Åþ...![00:41]Åþ...![00:41]Åþ...![00:42]Åþ...![00:42]Åþ...![00:43]Åþ...![00:43]Åþ...![00:44]Åþ...![00:44]Åþ...![00:45]Åþ...![00:45]Åþ...![00:46]Åþ...![00:46]Åþ...![00:47]Åþ...![00:47]Åþ...![00:48]Åþ...![00:48]Åþ...![00:49]Åþ...![00:49]Åþ...![00:50]Åþ...![00:50]Åþ...![00:51]Åþ...![00:51]Åþ...![00:52]Åþ...![00:52]Åþ...![00:53]Åþe.Åþ}...Åþe.Åþa¡Åþd.Åþ"0.module..: ****ddr2 256mx72 2gb 2r(8)@2x400mhz 1.8v.Åþ"...(tested @ 2x400mhz).Åþ".addr.(rowxcol.).: 14 x 10.Åþ".data (rankxbit).: 2 x 72.Åþ".internal banks.: 8.Åþ""burst.: mode=sequential, length=8.Åþ"*ac parameters.: cl=5, al=0, trcd=5, trp=5.Åþ".s/n spd.: a128f4f3.Åþ".test loop #.: 1.Åþ"..## pass: loop 1 ##.Åþ"..elapsed time.: 00:00:53.448.Åþa¢Åþc.............h..ÿÿÿÿ"ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ...s-(u.?€.....".. Åþ@.Åþe.Åþ....**pass - l001 @2x400mhzÅþ...![00:53]Åþ....transmit results ...Åþa¡Åþd.Åþ"0.module..: ddr2 256mx72 2gb 2r(8)@2x400mhz 1.8v.Åþ"...(tested @ 2x400mhz).Åþ".addr.(rowxcol.).: 14 x 10.Åþ".data (rankxbit).: 2 x 72.Åþ".internal banks.: 8.Åþ""burst.: mode=sequential, length=8.Åþ"*ac parameters.: cl=5, al=0, trcd=5, trp=5.Åþ".s/n spd.: .Åþ".test loop #.: 1.Åþ"..## pass: loop 1 ##.Åþ"..elapsed time.: 00:00:53.448.Åþa¢Åþ@.Åþ.** ..**

seems you're looking .find() method of string. using , wonderful utility python's string slices, can accomplish you're after.

as example:

# our string text we're after. blob = "filler text filler text begin we're after. end filler text." # utilize .find() find first occurrence of 2 given substrings. start = blob.find("begin") end = blob.find("end") # our result be: 'begin we're after. ' result = blob[start:end]

if wanted take step further, add together len() value of start string piece in order prevent begin beingness added , remove leading , trailing spaces blob.strip()

hope helps.

python string serial-port slice

No comments:

Post a Comment