from pathlib import Path
import os
folderpath = input("What is the absolute path to Superman's folder?")
mypath = Path(folderpath)
mypath = os.listdir(folderpath)
for files in mypath:
print ("Found one of Superman's's files..." + files)
#up to here, the code is good
for read in byfiles:
byfiles = ('mypath\\files')
byfiles.read_text()
if "Superman" in read:
print("Found Superman in file " + read)
Мне нужно найти файлы в пути ввода, найти слово «Супермен», а затем распечатать место, где было найдено слово. Я не могу заставить конкатенацию работать вместе с .read_text ().
Это вывод:
What is the absolute path to Superman's folder?C:\Users\OneDrive\Documents\Superman_files
Found one of Superman's files...boring_document.txt
Found one of Superman's files...eggs.txt
Found one of Superman's files...hello.txt
Found one of Superman's files...secret_document.txt
Found one of Superman's files...spam.txt
Любая помощь будет принята с благодарностью.