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
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_
>> 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
-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
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
> 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
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
-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
-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.
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
-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
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
12 matches
Mail list logo