Re: [Tutor] Increase performance of the script

2018-12-12 Thread Peter Otten
Steven D'Aprano wrote: > [...] >> In python 2.6 print statement work as print "Solution" >> however after import collection I have to use print with >> print("Solution") is this a known issue ? > > As Peter says, you must have run > > from __future__ import print_function > > to see this

Re: [Tutor] Increase performance of the script

2018-12-12 Thread Steven D'Aprano
On Wed, Dec 12, 2018 at 12:52:09AM -0500, Avi Gross wrote: > Asad, > > I wonder if an import from __future__ happened, perhaps in the version of > collections you used. Later versions of 2.x allow optional use of the 3.x > style of print. The effect of __future__ imports, like any other import,

Re: [Tutor] Increase performance of the script

2018-12-12 Thread Avi Gross
Of Asad Sent: Tuesday, December 11, 2018 10:38 AM To: tutor@python.org Subject: [Tutor] Increase performance of the script Hi All, I used your solution , however found a strange issue with deque : I am using python 2.6.6: >>> import collections >>> d = collections.deque('a

Re: [Tutor] Increase performance of the script

2018-12-11 Thread Steven D'Aprano
On Tue, Dec 11, 2018 at 09:07:58PM +0530, Asad wrote: > Hi All, > > I used your solution , however found a strange issue with deque : No you haven't. You found a *syntax error*, as the exception says: > >>> print 'Deque:', d > File "", line 1 > print 'Deque:', d >

[Tutor] Increase performance of the script

2018-12-11 Thread Asad
even D'Aprano) >3. Re: Increase performance of the script (Steven D'Aprano) > > > > ------ Forwarded message ------ > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Cc: > Bcc: > Date: Sun, 09 Dec 2018 21:17:53 +0100 > Subject: Re: [Tutor] I

Re: [Tutor] Increase performance of the script

2018-12-09 Thread Steven D'Aprano
On Sun, Dec 09, 2018 at 03:45:07PM +0530, Asad wrote: > Hi All , > > I have the following code to search for an error and prin the > solution . Please tidy your code before asking for help optimizing it. We're volunteers, not being paid to work on your problem, and your code is too

Re: [Tutor] Increase performance of the script

2018-12-09 Thread Steven D'Aprano
On Sun, Dec 09, 2018 at 03:45:07PM +0530, Asad wrote: > Hi All , > > I have the following code to search for an error and prin the > solution . > > /A/B/file1.log size may vary from 5MB -5 GB [...] > The problem I am facing in performance issue it takes some minutes to print > out the

Re: [Tutor] Increase performance of the script

2018-12-09 Thread Peter Otten
Asad wrote: > Hi All , > > I have the following code to search for an error and prin the > solution . > > /A/B/file1.log size may vary from 5MB -5 GB > > f4 = open (r" /A/B/file1.log ", 'r' ) > string2=f4.readlines() Do not read the complete file into memory. Read one line at a

Re: [Tutor] Increase performance of the script

2018-12-09 Thread Alan Gauld via Tutor
On 09/12/2018 10:15, Asad wrote: > f4 = open (r" /A/B/file1.log ", 'r' ) Are you sure you want that space at the start ofthe filename? > string2=f4.readlines() Here you read the entire file into memory. OK for small files but if it really can be 5GB that's a lot of memory being used. > for

[Tutor] Increase performance of the script

2018-12-09 Thread Asad
Hi All , I have the following code to search for an error and prin the solution . /A/B/file1.log size may vary from 5MB -5 GB f4 = open (r" /A/B/file1.log ", 'r' ) string2=f4.readlines() for i in range(len(string2)): position=i lastposition =position+1 while True: