Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #importing sys for automatically exit if there's error
- import sys
- #inputing file
- file_name = raw_input("Input your file name you want to read : ")
- #search file, exit when there's no file
- try:
- file = open(file_name, 'r')
- except:
- print "No such files"
- sys.exit(2)
- #inputting keyword
- word = raw_input("Input your text : ")
- #making lists of string
- strings = []
- #reading every char in file
- for string in file.read():
- #append every char into lists
- strings.append(string)
- #joining every char to one string
- strings = ''.join(str(e) for e in strings)
- #splitting every word by \n
- strings = strings.split('\n')
- #checking every word in lists
- for string in strings:
- if word == string:
- print word + " match!"
- #closing file
- file.close()
Add Comment
Please, Sign In to add comment