title: Python 3: How to create a text progress bar for downloading files?
body: <p>I have currently this:</p>
  
  <pre><code>def download_dropbox(url, pre_file_name):
      file = url[42:]
      file = file[:-5]
      file_name = pre_file_name + file
      print('Downloading from ' + url + ' to ' + file_name)
      print(file)
      u = urllib.request.urlopen(url)
      data = u.read()
      u.close()
  
      with open(file_name, "wb") as f:
          f.write(data)
      print('Download Completed from ' + url + ' and saved to ' + file_name)
  </code></pre>
  
  <p>This basically downloads files from dropbox and saves it to a directory. However I want to be able to have some sort of text progress bar like:</p>
  
  <hr>
  
  <p>[====      ]50%</p>
  
  <hr>
  
  <p>OR</p>
  
  <hr>
  
  <p>50%</p>
  
  <p>The hard part i would think is doing it with any external modules like the loading bar module, etc. Also, as the title states, I need it in python 3. Thank-you.</p>
  
  <p>Edit:</p>
  
  <p>Thanks to Martin Evans for the data read while loop and progress bar here is the end result of the code:</p>
  
  <pre><code>#Get the total number of bytes of the file to download before downloading
  print ("opening url:", url)
  u = urllib.request.urlopen(url)
  meta = u.info()
  print(str(meta).split())
  metaInfo = str(meta).split()
  print(len(metaInfo))
  print ("Content-Length:" + metaInfo[46] + " bytes")
  fileTotalbytes=int(metaInfo[46])
  
  data_blocks = []
  # total = int(metaInfo[46])
  total=0
  
  while True:
      block = u.read(1024)
      data_blocks.append(block)
      total += len(block)
      hash = ((60*total)//fileTotalbytes)
      print("[{}{}] {}%".format('#' * hash, ' ' * (60-hash), int(total/fileTotalbytes*100)), end="\r")
  
      if not len(block):
          break
  
  data=b''.join(data_blocks) #had to add b because I was joining bytes not strings
  u.close()
  
  with open('test.zip', "wb") as f:
          f.write(data)
  </code></pre>