jeremit0 wrote:
I have read a text file using the command
lines = myfile.readlines()
and now I want to seach those lines for a particular string. I was
hoping there was a way to "find" that string in a similar way as
searching simply a simple string. I want to do something like
lines.find.('my
linenums = [i for i in range(len(lines)) if lines[i].find(searchstring) >=0]
-Original Message-
From: Joshua Ginsberg [mailto:[EMAIL PROTECTED]
Sent: Friday, April 08, 2005 4:12 PM
To: [EMAIL PROTECTED]
Subject: Re: Equivalent string.find method for a list of strings
try:
filter(lam
Steven Bethard wrote:
jeremit0 wrote:
Steve Holden wrote:
If you want line numbers,. of course, then you can use
for linenum, line in enumerate(myfile.readlines()):
...
Remember that true to Python's philosophy numbering will start at zero.
Is this any better than:
lines = myfile.readli
jeremit0 wrote:
Steve Holden wrote:
If you want line numbers,. of course, then you can use
for linenum, line in enumerate(myfile.readlines()):
...
Remember that true to Python's philosophy numbering will start at zero.
Is this any better than:
lines = myfile.readlines()
for linenum
jeremit0 wrote:
Steve Holden wrote:
jeremit0 wrote:
harold fellermann wrote:
file.readlines() returns a list of lines. You can either call find
on each
element in this list, like:
for line in myfile.readlines() :
if line.find('my particular string') :
do_something()
I had thought that
Steve Holden wrote:
jeremit0 wrote:
harold fellermann wrote:
file.readlines() returns a list of lines. You can either call find on
each
element in this list, like:
for line in myfile.readlines() :
if line.find('my particular string') :
do_something()
I had thought that may be the only
On Fri, Apr 08, 2005 at 02:17:32PM -0400, jeremit0 wrote:
> I have read a text file using the command
>
> lines = myfile.readlines()
>
> and now I want to seach those lines for a particular string. I was
> hoping there was a way to "find" that string in a similar way as
> searching simply a si
harold fellermann wrote:
file.readlines() returns a list of lines. You can either call find on each
element in this list, like:
for line in myfile.readlines() :
if line.find('my particular string') :
do_something()
I had thought that may be the only way to do it, I was hoping for
somet
"jeremit0" <[EMAIL PROTECTED]> wrote:
>I have read a text file using the command
>
> lines = myfile.readlines()
>
> and now I want to seach those lines for a particular string. I was hoping
> there was a way to
> "find" that string in a similar way as searching simply a simple string. I
> want
try:
filter(lambda x: lines[x].find(searchstring) != -1, range(len(lines)))
That will return a list with the indices of every line containing a hit
for your search string.
-jag
<>Joshua Ginsberg -- [EMAIL PROTECTED]
Brainstorm Internet Network Operations
970-247-1442 x131
On Apr 8, 2005, at 1:52
jeremit0 wrote:
harold fellermann wrote:
file.readlines() returns a list of lines. You can either call find on
each
element in this list, like:
for line in myfile.readlines() :
if line.find('my particular string') :
do_something()
I had thought that may be the only way to do it, I was
Try:
filter(lambda x: x.find(searchstring) != -1, lines)
<>Joshua Ginsberg -- [EMAIL PROTECTED]
Brainstorm Internet Network Operations
970-247-1442 x131
On Apr 8, 2005, at 12:17 PM, jeremit0 wrote:
I have read a text file using the command
lines = myfile.readlines()
and now I want to seach those l
I have read a text file using the command
lines = myfile.readlines()
and now I want to seach those lines for a particular string. I was
hoping there was a way to "find" that string in a similar way as
searching simply a simple string. I want to do something like
lines.find.('my particular stri
13 matches
Mail list logo