Python split Canlog

Source: Internet
Author: User

The log exported via canoe usually has many IDs of data, how can I find a special signal under an ID? Using Python, you can simply do this step with the following code:

Description

The final effect is to split the log information, separate the IDs, and generate the file Log_id.csv folder separately.

1. Input folder required

2. Generate the _out folder.

3. No error handling

4. Use "[A-f|\d]{3}" to match the can ID

1 #log analy about CAN Signal for CANOE2 ImportOS3 ImportRe4 5Id_info = {}6fold_in = input ("Please input Folder in:")7Fold_out = fold_in +"_out"8 Os.mkdir (fold_out)9rep_id = R"[A-f|\d]{3}"Tenpatt_id =re.compile (rep_id) One defInfo_report (): A   " " - The information in the CAN log has a fixed number of digits.  - 0: Time stamp the 1:1/2 - 2:id - 3:rx/tx - 4:d + 5:data Length - 6:data Length Number info +   " " A   Pass at  - defDev_folder (folder_in): -    forFiinchOs.listdir (folder_in): -     #Open File -With open (Os.path.join (FOLDER_IN,FI),"R") as file: -       #traversing file Lines in        forLineinchFile: -         #split the file, remove the space, remove the comma before and after toA = Re.sub ('\s+',',', line). Strip (",") +         #determines whether the list has more than 3 elements, and whether the 3rd is an ID. -         ifLen (A.split (",")) > 2 andPatt_id.match (A.split (",") [2]): the           ifA.split (",") [2]inchId_info.keys (): *             #If you are in the dictionary, write the information directly to the file $             PassPanax Notoginseng           Else: -           #Create a new file, associate a dictionary theId_info[a.split (",") [2]] = open ((Os.path.join (Fold_out +"\\"+"Log_"+ A.split (",") [2]) +". csv"),"W") +Id_info[a.split (",") [2]].write (A +"\ n") A           #Print (A.split (",") [0]) the    forKeyinchId_info: + id_info[key].close () -  $ if __name__=='__main__': $ Dev_folder (fold_in) -       

Python split Canlog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.