1

I ran a Python program and I am getting the following error as below:

   File :...,line ...,in <module>  
   results = parse_file(text, ['stderr'], ['ERROR', 'WARN'])
  
   Fie :....,line ...,in parse_file
   all_containers=re.split('^Container:container_',text,flags=re.MULTILINE)
   TypeError: split() got an unexpected keyword argument 'flags'

Below is my code:

def parse_file(text,filter_log_types=None,filter_content_types=None):
    full_text_lines=text.split('\n')

    results=[]

    all_containers=re.split('^Container:container_',text,flags=re.MULTILINE)

    for item in all_containers[1:]:
        data=parse_container(item, full_text_lines, filter_log_types, filter_content_types)
        results.append(data)

    return results 

if __name__ == '__main__':
    text = open("lg.txt").read()
    results = parse_file(text, ['stderr'], ['ERROR', 'WARN'])

I am using Python 2.6.6. Please help me to sort out this error. Thanks a lot!

2
  • 1
    Python 2.6's re.split() doesn't have the 'flags' kwargs as noted here: docs.python.org/2.6/library/re.html Commented Jul 14, 2020 at 7:20
  • Is there any alternate for that ?So that I can implement it in my program. Commented Jul 14, 2020 at 7:24

1 Answer 1

1

The flags keyword argument was added in python 2.7 version, so it raises an error in your code

Try to use re.compile() in combination with split()

all_containers=re.compile('^Container:container_',flags=re.MULTILINE).split(text)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.