Re: Look for a string on a file and get its line number

2008-01-08 Thread jcvanelst
On 8 jan, 03:19, Horacius ReX <[EMAIL PROTECTED]> wrote: > Hi, > > I have to search for a string on a big file. Once this string is > found, I would need to get the number of the line in which the string > is located on the file. Do you know how if this is possible to do in > python ? > > Thanks h

Re: Look for a string on a file and get its line number

2008-01-08 Thread Horacius ReX
Hi, thanks for the help. Then I got running the following code; #!/usr/bin/env python import os, sys, re, string, array, linecache, math nlach = 12532 lach_list = sys.argv[1] lach_list_file = open(lach_list,"r") lach_mol2 = sys.argv[2] # name of the lachand mol2 file lach_mol2_file = open(lach_

Re: Look for a string on a file and get its line number

2008-01-08 Thread Tim Chase
>> I have to search for a string on a big file. Once this string >> is found, I would need to get the number of the line in which >> the string is located on the file. Do you know how if this is >> possible to do in python ? > > This should be reasonable: > for num, line in enumerate(open

Re: Look for a string on a file and get its line number

2008-01-08 Thread Jeroen Ruigrok van der Werven
-On [20080108 12:59], Wildemar Wildenburger ([EMAIL PROTECTED]) wrote: >Style note: >May I suggest enumerate (I find the explicit counting somewhat clunky) >and maybe turning it into a generator (I like generators): Sure, I still have a lot to discover myself with Python. I'll study your example

Re: Look for a string on a file and get its line number

2008-01-08 Thread Wildemar Wildenburger
Jeroen Ruigrok van der Werven wrote: > line_nr = 0 > for line in big_file: > line_nr += 1 > has_match = line.find('my-string') > if has_match > 0: > print 'Found in line %d' % (line_nr) > Style note: May I suggest enumerate (I find the explicit counting somewhat clunky) and ma

RE: Look for a string on a file and get its line number

2008-01-08 Thread Ryan Ginstrom
> On Behalf Of Horacius ReX > I have to search for a string on a big file. Once this string > is found, I would need to get the number of the line in which > the string is located on the file. Do you know how if this is > possible to do in python ? This should be reasonable: >>> for num, line

Re: Look for a string on a file and get its line number

2008-01-08 Thread Martin Marcher
Jeroen Ruigrok van der Werven wrote: > -On [20080108 09:21], Horacius ReX ([EMAIL PROTECTED]) wrote: >>I have to search for a string on a big file. Once this string is >>found, I would need to get the number of the line in which the string >>is located on the file. Do you know how if this is possi

Re: Look for a string on a file and get its line number

2008-01-08 Thread Jeroen Ruigrok van der Werven
-On [20080108 09:51], John Machin ([EMAIL PROTECTED]) wrote: >Make that >= > >| >>> 'fubar'.find('fu') Or even just: if 'my-string' in line: ... Same caveat emptor applies though. -- Jeroen Ruigrok van der Werven / asmodai イェルーン ラウフロック ヴァン デル ウェルヴェン http://www.in-nomine.org/ | http://www.r

Re: Look for a string on a file and get its line number

2008-01-08 Thread Jeroen Ruigrok van der Werven
-On [20080108 09:51], John Machin ([EMAIL PROTECTED]) wrote: >Make that >= Right you are. Sorry, was doing it quickly from work. ;) And I guess the find will also be less precise if the word you are looking is a smaller part of a bigger word. E.g. find 'door' in a line that has 'doorway' in it.

Re: Look for a string on a file and get its line number

2008-01-08 Thread John Machin
On Jan 8, 7:33 pm, Jeroen Ruigrok van der Werven <[EMAIL PROTECTED] nomine.org> wrote: > -On [20080108 09:21], Horacius ReX ([EMAIL PROTECTED]) wrote: > > >I have to search for a string on a big file. Once this string is > >found, I would need to get the number of the line in which the string > >is

Re: Look for a string on a file and get its line number

2008-01-08 Thread Jeroen Ruigrok van der Werven
-On [20080108 09:21], Horacius ReX ([EMAIL PROTECTED]) wrote: >I have to search for a string on a big file. Once this string is >found, I would need to get the number of the line in which the string >is located on the file. Do you know how if this is possible to do in >python ? (Assuming ASCII, ot

Look for a string on a file and get its line number

2008-01-08 Thread Horacius ReX
Hi, I have to search for a string on a big file. Once this string is found, I would need to get the number of the line in which the string is located on the file. Do you know how if this is possible to do in python ? Thanks -- http://mail.python.org/mailman/listinfo/python-list