accessing a text file

Benjamin Kaplan benjamin.kaplan at case.edu
Sun Sep 5 18:01:19 EDT 2010


On Sun, Sep 5, 2010 at 5:47 PM, 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
>

Please do us a favor and at least try to figure things out on your
own, rather than coming here every time you have a question. The very
first result when you try searching "python read text file" is the
section in the Python tutorial that explains how to do this.

http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files



More information about the Python-list mailing list