Re: How can I verify if the regex exist in a file without reading ?

2018-06-15 Thread francois . rabanel
Le vendredi 15 juin 2018 12:36:40 UTC+2, Steven D'Aprano a écrit : > On Fri, 15 Jun 2018 01:01:03 -0700, francois.rabanel wrote: > > > I work with a file which contains millions lines, a simply file.read() > > and I'm running out of memory > > Assuming each line is on average a hundred characters

Re: How can I verify if the regex exist in a file without reading ?

2018-06-15 Thread Steven D'Aprano
On Fri, 15 Jun 2018 01:01:03 -0700, francois.rabanel wrote: > I work with a file which contains millions lines, a simply file.read() > and I'm running out of memory Assuming each line is on average a hundred characters long, a million lines is (approximately) 100 MB. Even on a computer with only

Re: How can I verify if the regex exist in a file without reading ?

2018-06-15 Thread francois . rabanel
Le vendredi 15 juin 2018 02:42:12 UTC+2, Cameron Simpson a écrit : > On 15Jun2018 00:24, Steven D'Aprano > wrote: > >On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: > >> Francois, unless your regex can cross multiple lines it is better to > >> search files like this: > >> > >> with o

Re: How can I verify if the regex exist in a file without reading ?

2018-06-14 Thread Cameron Simpson
On 15Jun2018 00:24, Steven D'Aprano wrote: On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: Francois, unless your regex can cross multiple lines it is better to search files like this: with open(the_filename) as f: for line in f: ... search the line for the regexp ... T

Re: How can I verify if the regex exist in a file without reading ?

2018-06-14 Thread Steven D'Aprano
On Fri, 15 Jun 2018 10:00:59 +1000, Cameron Simpson wrote: > Francois, unless your regex can cross multiple lines it is better to > search files like this: > > with open(the_filename) as f: > for line in f: > ... search the line for the regexp ... > > That way you only need to keep o

Re: How can I verify if the regex exist in a file without reading ?

2018-06-14 Thread Cameron Simpson
On 14Jun2018 16:54, Steven D'Aprano wrote: On Thu, 14 Jun 2018 09:26:44 -0700, francois.rabanel wrote: My problem is, if I work on a huge file, I'll try to avoid to read the file because it will be crash my computer :) How does reading a file crash your computer? Likely because he tried to

Re: How can I verify if the regex exist in a file without reading ?

2018-06-14 Thread Steven D'Aprano
On Thu, 14 Jun 2018 09:26:44 -0700, francois.rabanel wrote: > Hi, > > Here is my script : > > It propose to replace some words in a file with a regular expression. It > create a copy to write on it, and if there isn't an error, it delete the > original by the copy with "os.rename" at the end. >

How can I verify if the regex exist in a file without reading ?

2018-06-14 Thread francois . rabanel
Hi, Here is my script : It propose to replace some words in a file with a regular expression. It create a copy to write on it, and if there isn't an error, it delete the original by the copy with "os.rename" at the end. My problem is, if I work on a huge file, I'll try to avoid to read the file