Join date: May 14, 2022

Solucionariosoxfordmoveon1bachilleratoingles nikhear




EpicopterDronesGrandPr A: The original version of your question didn't have code to show what you were actually trying to accomplish, but from the comments, it seems like you are trying to do something like this: def process(filename, lookup_filename): with open(filename, 'r') as fin: for line in fin: if lookup_filename in line: print(line, file=sys.stdout) return print('ready to go') for filename in glob.glob('*'): print(filename) process(filename, filename) I think the idea is to check each line of each file in your directory for a match to a filename in another file. The problem is that this isn't going to work. What you have as filename in the second parameter, lookup_filename, is going to be looked up in the current directory. But this is where the problem starts: the glob module doesn't care about file extension, and it will find all the files and subdirectories in your current directory. And all those files and subdirectories are going to have the same filename, filename, in the second parameter. So, you're going to get nothing but matches for filename in the first file. I assume what you really want is to generate all of the lines in all of the files that you find in a directory. You can do that with a generator function, like this: def process(directory): for filename in os.listdir(directory): with open(os.path.join(directory, filename)) as fin: for line in fin: if line.startswith('filename'): yield line.strip() The trick is to use os.listdir(directory) to get a list of all of the files in the directory. Then, you can process each




Solucionariosoxfordmoveon1bachilleratoingles nikhear
More actions