How to display mb/s instead of b/s in progressbar and Python?
<p>I am trying to change the way progressbar (version 2) displays the transferred/total file size in Python 3. Here's the code:     </p>

<pre><code>import progressbar
import requests

url = 'http://download.openbricks.org/sample/H264/big_buck_bunny_1080p_H264_AAC_25fps_7200K_short.MP4'

request = requests.get(url, stream=True)

file         = open('test.mp4', 'wb')
file_size    = int(request.headers['Content-Length'])
file_size_mb = round(file_size / 1024 / 1024,2)

chunk_sz = 512

widgets = [progressbar.Bar(marker="#",left="[",right="]"),
           progressbar.Percentage()," | ",
           progressbar.FileTransferSpeed()," | ",
           progressbar.SimpleProgress()," | ",
           progressbar.ETA()]

bar = progressbar.ProgressBar(widgets=widgets, maxval=file_size).start()

i = 0

for chunk in request.iter_content(chunk_size=chunk_sz):
    file.write(chunk)
    i += len(chunk)
    bar.update(i)

bar.finish()
print('File size: {0} MB'.format(file_size_mb))

file.close()
</code></pre>

<p>The output:</p>

<blockquote>
  <p>[#########################] 91% | 741.3 KiB/s | 3397632 of 3714474 | Time: 00:00:08</p>
  
  <p>File size: 3.54 MB</p>
</blockquote>

<p>I want to be able to make the "<strong>3397632</strong> of <strong>3714474</strong>" be displayed in the MB format (like in the <em>file_size_mb</em> variable), not in Bytes as it is being displayed by progressbar by default.</p>

<p>I've read the docs in <a href="http://progressbar-2.readthedocs.io/en/latest/" rel="nofollow" title="Welcome to Progress Barâs documentation!">Progress Barâs documentation</a> but I couldn't find the answer to my question in any of the examples given there.</p>

<p>From <code>progressbar</code> documentation :</p>

<pre><code>class progressbar.widgets.SimpleProgress(format=â%(value)d of %(max_value)dâ,
max_width=None, **kwargs)

Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase

Returns progress as a count of the total (e.g.: â5 of 47â)
</code></pre>

<p>So I'd assume you can use the <code>format</code> parameter to do what you need.</p>

<pre><code>widgets = [progressbar.Bar(marker="#",left="[",right="]"),
           progressbar.Percentage()," | ",
           progressbar.FileTransferSpeed()," | ",
           progressbar.SimpleProgress(format='%(value/1024/1024)d of %(max_value/1024/1024)d')," | ",
           progressbar.ETA()]
</code></pre>

<p>Another way would consist in getting getting the output from simpleProgress, parse it to get the values, and do the maths manually.</p>

python python-3.x format progress-bar transfer