I am trying to search some files through regular expression, my target files look like: 'Myfile_200_2018.csv';'Myfile_100_2018.csv'....
For example, the following code keeps give the error: expected string or bytes-like object for Regex in Python.
I searched same error from Google, but I think my game_id is a string right? So I am not sure which part causes the error.
import os
import re
allfiles = os.listdir('.')
csv_files = [filename for filename in allfiles if filename.endswith('.csv')]
game_id='100'
re.search(r'(Myfile_%s_\d{4}.csv$)'%game_id, csv_files)
csv_filesneeds to be a string, not a list of strings.csv_files = [filename for filename in allfiles if filename.endswith('.csv') and re.search((r"Myfile_%s_\d{4}.csv$" % game_id), filename)]?