title: Why does my tqdm progress bar display on a new line for every iteration?
body: <p>I'm working on a personal project where I grab data from a website using requests. One of the files is quite large so I wanted to include a progress bar as a &quot;sign of life&quot;.</p>
  <p>The downloading bit works but the progress bar constantly outputs on a new line even though I've based it on the examples from the tqdm docs.</p>
  <p>Code below:</p>
  <pre class="lang-py prettyprint-override"><code>def download_data() -&gt; BinaryIO:
      &quot;&quot;&quot;Download the two zipped data packages
      from the Open Power System Data website.
  
      Returns
      -------
      BinaryIO
          Saves the two packages in Data/Raw
      &quot;&quot;&quot;
      urls = [GENERATION_CAPACITY_URL, TIME_SERIES_URL]
  
      for url in urls:
          # Gets the filename directly from the url, saves us having to name it
          url_filename = Path(urlparse(url).path).name
  
          # Check if exists before doing lengthy download
          if not Path.exists(RAW_DATA / url_filename):
  
              # Stream = True because files are quite large
              with requests.get(url, stream=True) as response:
  
                  # Check connection first, will raise HTTPError if bad
                  response.raise_for_status()
  
                  chunk_size = 1024 * 1024
  
                  print(f&quot;Downloading {url_filename}&quot;)
  
                  with open(RAW_DATA / url_filename, &quot;wb&quot;) as f:
                      with tqdm(
                          unit=&quot;B&quot;,
                          unit_scale=True,
                          unit_divisor=1024,
                          total=int(response.headers.get(&quot;content-length&quot;, 0)),
                      ) as pbar:
  
                          for chunk in response.iter_content(chunk_size=chunk_size):
                              f.write(chunk)
                              pbar.update(len(chunk))
  
          else:
              print(f&quot;File: {url_filename} already exists&quot;)
  </code></pre>
  <p>I call the function below in a name == main condition (not shown for clarity)</p>
  <p>When I run the file I get a progress bar that updates as the file downloads, but each update seems to render a new progress bar on a new line rather than one permanent progress bar where the bar just moves along the screen (as you'd expect)</p>
  <p>i.e. instead of:</p>
  <pre class="lang-sh prettyprint-override"><code>[|||||| 3%]
  </code></pre>
  <p>I get</p>
  <pre class="lang-sh prettyprint-override"><code>[| 1%]
  [| 1%]
  [|| 2%]
  [||| 3%]
  </code></pre>
  <p>On and on until it finishes.</p>
  <p>Not sure if I'm doing something basic wrong, I just can't figure it out!</p>