Display lines within {} in Python -


i need print lines inside {} of "list a" using python. i'm reading out lines , searching string list a not sure how display lines within {}.

example:

  list   {     name,     place,     animal,     thing   }   list b  {     cat,     dog,  } 

update: tried print(re.compile('list a\n\{\n(.*)\n\}', re.multiline | re.dotall) .search(s).groups()[0]) mentioned did not work. gave me error group not found.

i tried find string "list b" dint work either. have pasted code below.

import sys input_file = open(r'path/input.txt')  output_file = open('path/output.txt','w') input_file_read = input_file.read() line in str(input_file_read):     output_file.write(line)     if line == "list b":         next(line)         print line  

input_file_read input file open read , output_file output file writing output.

question: can tell me why if statement not search string?? , how can search list b among many list?? have given sample of input file there many list in ~ 30 same format though. help!!!

a more generic example handle list name:

import re s = ''  # put content s match in re.finditer(r'list\s+(\w+)\s*\{(.*?)\}', s, re.dotall)     print '-------new list--------'     print 'name of list:', m.group(1)     print 'content of list:', m.group(2) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -