I tried to get some string between two keywords from a large text file with the following pattern searching each line by line and print it as well as store in another text file
'Event_WheelMonitorReleased' (253) 'Event_WheelMonitorPressed' (252) 'Event_WheelMonitorPressed' (252) 'Event_WheelMonitorPressed' (252)
Here I would like to extract only the strings inbetween EVENT()
Here I would say I need X_0_Gui_Menu_610_Menu_Status_System
I tried the following code
def get_navigated_pages():
os.chdir('log_file')
log_file = open('messages','r')
data = log_file.read()
navigated_pages = re.findall(r'EVENT(X(.*?)) ',data,re.DOTALL|re.MULTILINE)
with open('navigated_page_file', 'w') as navigated_page_file:
navigated_page_file.write(navigated_pages)
I expected the output in the text file to be something like this
X_0_Gui_Menu_650_Menu_Status_Version
X_0_Gui_Menu_610_Menu_Status_System
X_0_Gui_Menu_670_Menu_Status_Media
As mentioned above I would like to get the output only which is starting with X_0 and ignoring starting with other keywords
('Navigated pages: ', [])at the print statement and nothing at all in the text filewithbeforeopen) and multiple logic and spelling errors (navigated_page_fileversusnavigated_pages_file, giving a list object towrite). In your comment you mention a print statement but show none in your code. You should show your actual code.