Ok, so I saw other questions, but I ran into a unique problem. I need to open the file in binary mode in order to read it (I do not understand why, but it works). and I can easily print the lines of the file without any problems. But when I try to find a specific string using re.search , I have problems because I have a string pattern and byte objects. Here is what I still have:
input_file = open(input_file_path, 'rb', 0) for line in input_file: if re.search("enum " + enum_name, line, 0): print("Found it") print(line) exit()
enum_name is user input, so I really need to know how I can use both a string and a variable in my search for a file opened in binary mode (or how to open this file not in binary mode, I get a jar 't have an unbuffered error text input / output, if not in binary mode). I tried to make my template for binary search, but I do not know what to do with the variable when I do this.
source share