Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- filename = input("Give me a file name: ")
- phrase = input("What phrase you want to find: ")
- def phrase_lookup(filename, phrase):
- try:
- with open(filename, "r") as f:
- for line_num, line in enumerate(f, 1):
- if phrase in line:
- bold_phrase = line.replace(phrase, f"\033[1m{phrase}\033[0m")
- print(f"Found '{phrase}' in line {line_num}: {bold_phrase.strip()}")
- except FileNotFoundError:
- print(f"The file {filename} does not exists.")
- if __name__=="__main__":
- phrase_lookup(filename, phrase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement