Francis Girard wrote:
Le mardi 1 Mars 2005 16:52, Marc Huffnagle a écrit :
[line for line in document if (line.find('word') != -1 \
and line.find('wordtwo') != -1)]
Hi,
Using re might be faster than scanning the same line twice :
My understanding of the second questio
Oops, made a mistake.
Marc Huffnagle wrote:
Dasacc
There is a better (faster/easier) way to do it than using the re module,
the find method of the string class.
[EMAIL PROTECTED] wrote:
(1) How do I perform a search for "word" and have it return every line
that this instance is found?
Dasacc
There is a better (faster/easier) way to do it than using the re module,
the find method of the string class.
[EMAIL PROTECTED] wrote:
(1) How do I perform a search for "word" and have it return every line
that this instance is found?
[line for line in document if line.find('a') != -1]
(2)
Jeff Epler wrote:
There's another little-known fact about Python: No string is permitted
to end with a backslash! You might think that variations like
r'\'
or
""\""
would allow you to create this elusive value, but you'd mistaken!
Now, this may not bother Unix sysadmins, but t
When you read a file with that method, is there an implied close() call
on the file? I assume there is, but how is that handled?
Caleb Hattingh wrote:
Peter, that was very clear, thanks.
So not only is
for line in file(...):
# do stuff
the most elegant, it is also the fastest. file.readlines(
Steve Holden wrote:
Marc Huffnagle wrote:
I have a number of variables that I want to modify (a bunch of strings
that I need to convert into ints). Is there an easy way to do that
other than saying:
> a = int(a)
> b = int(b)
> c = int(c)
I tried
> [i = int(i) for i in [a, b,
I have a number of variables that I want to modify (a bunch of strings
that I need to convert into ints). Is there an easy way to do that
other than saying:
> a = int(a)
> b = int(b)
> c = int(c)
I tried
> [i = int(i) for i in [a, b, c]]
but that didn't work because it was creating a list with