0

I just want to check the the number of treated lines during program running. (I treat txt file with about million lines.)

to check the number of treated lines during running time, I use this code below

lineCnt = 0
for line in lines:
    lineCnt += 1
    if lineCnt % 2500 == 0:
        sys.stdout.write('.')
    if lineCnt % 100000 == 0:
        print("")

I expected printing 1 dot on screen when 2500 lines are treated. but, I just can see printing 40 dots at same time. when 100000 lines are treated.

how can i fix it to get the result exactly what I want? T.T

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
이승원
  • 101
  • 4

2 Answers2

2

Try adding sys.stdout.flush() after sys.stdout.write('.').

Of you could use print there. If you do not want new line after dot, call print like this:

In Python 3.X: print('.', end='')

In Python 2.X: print '.',

monsur
  • 45,581
  • 16
  • 101
  • 95
del-boy
  • 3,556
  • 3
  • 26
  • 39
0

Do you want to print 40 dots at once when there are very many dots?

lineCnt = 0
for line in lines:
    lineCnt += 1
    if lineCnt > 100000:
        if lineCnt % 100000 == 0:
            print("." * 40)
    elif lineCnt % 2500 == 0:
        sys.stdout.write('.')
User
  • 14,131
  • 2
  • 40
  • 59