I am trying to create a function that will search a fixed line of text for a word or phrase. Once that is completed, I am to try and pass the line of text and the word as parameters. Can someone help lead me in the right direction. I have literally just started learning this language for week. Im using python 3.1. Im using the terminal window in mac for python. Below is what I have done so far, which is to see if I can search a file for a specific string and return the results. The error message is also shown below. What am I doing wrong?
>>> def search_linetest(): ... path= '/Users/jolie_tia/Documents' ... dir= os.listdir(path) ... for file in dir: ... open('/Users/jolie_tia/Documents/sample.txt') ... s= file.read() ... x= text.find('I was scared to pieces.') ... if x != -1: ... print ('Line was found starting at character', x) ... else: ... print ('Line not found') ... >>> >>> linetest() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 2, in linetest IOError: [Errno 2] No such file or directory: 'Users/jolie_tia/Documents/sample.text'