the_msp
Lifetime Supporting Member
I have a text file with machine data, wanting to parse through it and extract PCB ID and date time.
The string I'm interested in is:
I'm interested in the first 3 digits of the PCB ID and the TestTime
This is my current approach but PCB ID and datetime naturally change with each part. How can I wildcard in so it starts at DataFile, ends at TestCell, and I can count from the start and end point to extract the data I want?
Or is there a better way?
The string I'm interested in is:
DataFile contents: Process= Servo Press PCBID= **************** TestTime= 22/12/2017 10:36:52 TestCell
I'm interested in the first 3 digits of the PCB ID and the TestTime
Code:
string = "DataFile contents: Process= Servo Press*TestCell"
file = open(filepath)
for line in file:
if line.find(string) != -1:
pos1 = string.find(string) + 46
pos2 = string.find(string) + 49
pos3 = string.find(string) - 19
pos4 = string.find(string) - 1
PCB= string[pos1:pos2]
DT = string[pos3:pos4]
This is my current approach but PCB ID and datetime naturally change with each part. How can I wildcard in so it starts at DataFile, ends at TestCell, and I can count from the start and end point to extract the data I want?
Or is there a better way?