accessing a text file

Nitin Pawar nitinpawar432 at gmail.com
Sun Sep 5 17:59:23 EDT 2010


may be something like this

f = open ("file",r)
data = f.read()
f.close

if word in data:
    print word, "is present in file"

On Mon, Sep 6, 2010 at 3:17 AM, Baba <raoulbia at gmail.com> wrote:

> level: beginner
>
> how can i access the contents of a text file in Python?
>
> i would like to compare a string (word) with the content of a text
> file (word_list). i want to see if word is in word_list. let's assume
> the TXT file is stored in the same directory as the PY file.
>
> def is_valid_word(word, word_list)
>
>
> thanks
> Baba
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Nitin Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100906/91a42648/attachment-0001.html>


More information about the Python-list mailing list