简体   繁体   中英

Progress bar for uploading file in Python

I want to upload one large .ndjson to Python. Is there a way to add a progress bar so that I know how much of the file is uploaded?

import json
import pandas as pd


df = map(json.loads, open('dump.ndjson'))
df = pd.DataFrame.from_records(records)

This is the way to upload the file. Code is good because when I split the file into 100 pieces I can upload one by one. But is there a way to add a progress bar so that I can upload the file at once and to see the progress of uploading?

PS. Im not thinking on gui, I have head for tqdm progress bar. I was thinking something like that, so that I can see progress in my console

If the question is about a GUI, there's PySimpleGUI that allows easy using of progress bars that rely on Tk, Wx or Qt frameworks. This works on Linux / Windows.

Example from their cookbook:

import PySimpleGUI as sg

# layout the window
layout = [[sg.Text('Uploading...')],
          [sg.ProgressBar(100, orientation='h', size=(20, 20), key='progressbar')],
          [sg.Cancel()]]

# create the window`
window = sg.Window('My Program Upload', layout)
progress_bar = window['progressbar']
# loop that would normally do something useful
for i in range(1000):
    # check to see if the cancel button was clicked and exit loop if clicked
    event, values = window.read(timeout=10)
    if event == 'Cancel'  or event == sg.WIN_CLOSED:
        break
  # update bar with loop value +1 so that bar eventually reaches the maximum
    progress_bar.UpdateBar(i + 1)
  # TODO: Insert your upload code here
# done with loop... need to destroy the window as it's still open
window.close()

I use that kind of progress bar and keep my upload function in a separate thread so the UI is non blocking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM