f = open("myfile.txt", "r")
list_one = f.read().splitlines()
f.close()

Or use f.readlines(), which would do the same thing IIRC?

On Fri, 04 Sep 2009 07:46:42 -0700, Stephen Fairchild <someb...@somewhere.com> wrote:

joy99 wrote:

Dear Group,

I have a file. The file has multiple lines. I want to get the line
number of any one of the strings.
Once I get that I like to increment the line number and see the string
of the immediate next line or any following line as output. The
problem as I see is nicely handled in list,

like list_one=["god","earth","sky","cloud","rain"]
      list_one[0]="god"
      list_one[2]="sky"

but can it be for string and file?

It's easy to read a file into a list.

f = open("myfile.txt", "r")
list_one = f.read().splitlines()
f.close()



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to