Re: Module RE, Have a couple questions

2005-03-01 Thread Marc Huffnagle
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

Re: Module RE, Have a couple questions

2005-03-01 Thread Marc Huffnagle
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?

Re: Module RE, Have a couple questions

2005-03-01 Thread Marc Huffnagle
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)

Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread Marc Huffnagle
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

Re: Basic file operation questions

2005-02-08 Thread Marc Huffnagle
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(

Re: List mapping question

2005-02-03 Thread Marc Huffnagle
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,

List mapping question

2005-02-03 Thread Marc Huffnagle
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