简体   繁体   中英

How to write a specific part of a line in writeline

I have an error log, which I need to writeline the error code from. The log usually ends in something like: "Error, problem number: 9478389439"

my code starts with:

for line in lines:
    if line.find('problem number:') >= 0:
      f.writeline(?????

I need to create a list with the error codes, and expand on it with other things. This json is being generated for multiple analysis. I can't just throw these on a db and find the results, I need a proper writeline .

you can try:

for line in lines:
    if line.find('problem number:') >= 0:
        f.write(line.split('problem number:')[-1].strip())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM