0

I've been trying to write my output to the same line and have already searched Stackoverflow. It seems what works for everyone else is not working for me !! Here's my code:

count = float(len(emails))
counter = 0
symbols = ["/","-","|","\\","|"]
for e in emails:
    print '%s inserting emails %s%%\r' % (symbols[counter % 5], counter / count * 100),
    sys.stdout.flush()
    counter += 1    

The comma after the print still causes a carriage return !!

| inserting emails 3.312%
\ inserting emails 3.313%
| inserting emails 3.314%
/ inserting emails 3.315%
- inserting emails 3.316%
| inserting emails 3.317%
\ inserting emails 3.318%

What is the issue?

Farhad Alizadeh Noori
  • 2,276
  • 17
  • 22

1 Answers1

0

There is a chance your console does not support this. You can test your functionality by using the other method of printing without a newline (using sys).

The way to do this is to use sys.stdout.write('') command. As an example:

import sys 
sys.stdout.write('hello %d' %(1))

your output will be

>>> sys.stdout.write('hello %d' %(1))
hello 1>>> 
Jason B
  • 7,097
  • 8
  • 38
  • 49