Repository: tqdm/tqdm (Python)

Issue:
No output on Python3
On both Python 3.5 and 3.6 on Ubuntu I get no output from this script.

If I swap the order of `nothing` and `pb.set_description` then it magically works.

```python
#!/usr/bin/env python

from tqdm import tqdm

# didn't want to use time.sleep to ensure nothing was happening there; this is a real busy loop
def nothing(x):
    for i in range(x):
        for j in range(x):
            for k in range(x):
                pass


def main():
    with tqdm(list(range(100))) as pb:
        for thing in pb:
            pb.set_description('%-15s' % thing)
            nothing(300)


if __name__ == '__main__':
    main()
```


Hints:

Patch:
diff --git a/examples/redirect_print.py b/examples/redirect_print.py
--- a/examples/redirect_print.py
+++ b/examples/redirect_print.py
@@ -57,8 +57,9 @@ def some_fun(i):
     # tqdm needs the original stdout
     # and dynamic_ncols=True to autodetect console width
     for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
-        sleep(.5)
+        # order of the following two lines should not matter
         some_fun(i)
+        sleep(.5)
 
 # After the `with`, printing is restored
 print("Done!")
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -175,8 +175,8 @@ def execute_makefile_commands(commands, alias, verbose=False):
     platforms=['any'],
     packages=['tqdm'],
     entry_points={'console_scripts': ['tqdm=tqdm._main:main'], },
-    data_files = [('man/man1', ['tqdm.1'])],
-    package_data = {'': ['CONTRIBUTING.md', 'LICENCE', 'examples/*.py']},
+    data_files=[('man/man1', ['tqdm.1'])],
+    package_data={'': ['CONTRIBUTING.md', 'LICENCE', 'examples/*.py']},
     long_description=README_rst,
     classifiers=[
         # Trove classifiers
diff --git a/tqdm/_tqdm.py b/tqdm/_tqdm.py
--- a/tqdm/_tqdm.py
+++ b/tqdm/_tqdm.py
@@ -283,10 +283,10 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False,
             [default: '{l_bar}{bar}{r_bar}'], where
             l_bar='{desc}: {percentage:3.0f}%|' and
             r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
-                  '{rate_fmt}{postfix}]'
+              '{rate_fmt}{postfix}]'
             Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
-                percentage, rate, rate_fmt, rate_noinv, rate_noinv_fmt,
-                rate_inv, rate_inv_fmt, elapsed, remaining, desc, postfix.
+              percentage, rate, rate_fmt, rate_noinv, rate_noinv_fmt,
+              rate_inv, rate_inv_fmt, elapsed, remaining, desc, postfix.
             Note that a trailing ": " is automatically removed after {desc}
             if the latter is empty.
         postfix  : str, optional
@@ -1212,7 +1212,7 @@ def set_postfix_str(self, s='', refresh=True):
     def moveto(self, n):
         self.fp.write(_unicode('\n' * n + _term_move_up() * -n))
 
-    def clear(self, nomove=False, nolock=False):
+    def clear(self, nolock=False):
         """
         Clear current bar display
         """
@@ -1221,14 +1221,10 @@ def clear(self, nomove=False, nolock=False):
 
         if not nolock:
             self._lock.acquire()
-        if not nomove:
-            self.moveto(self.pos)
-        # clear up the bar (can't rely on sp(''))
-        self.fp.write('\r')
-        self.fp.write(' ' * (self.ncols if self.ncols else 10))
+        self.moveto(self.pos)
+        self.sp('')
         self.fp.write('\r')  # place cursor back at the beginning of line
-        if not nomove:
-            self.moveto(-self.pos)
+        self.moveto(-self.pos)
         if not nolock:
             self._lock.release()
 
@@ -1242,10 +1238,7 @@ def refresh(self, nolock=False):
         if not nolock:
             self._lock.acquire()
         self.moveto(self.pos)
-        # clear up this line's content (whatever there was)
-        self.clear(nomove=True, nolock=True)
-        # Print current/last bar state
-        self.fp.write(self.__repr__())
+        self.sp(self.__repr__())
         self.moveto(-self.pos)
         if not nolock:
             self._lock.release()


Test patch:
diff --git a/tqdm/tests/tests_tqdm.py b/tqdm/tests/tests_tqdm.py
--- a/tqdm/tests/tests_tqdm.py
+++ b/tqdm/tests/tests_tqdm.py
@@ -1362,8 +1362,7 @@ def test_write():
             assert after_err_res == [u'\rpos0 bar:   0%',
                                      u'\rpos0 bar:  10%',
                                      u'\r      ',
-                                     u'\r\r      ',
-                                     u'\rpos0 bar:  10%']
+                                     u'\r\rpos0 bar:  10%']
             assert after_out == s + '\n'
     # Restore stdout and stderr
     sys.stderr = stde