-1

我想将一个大文件上传.ndjson到 Python。有没有办法添加进度条以便我知道上传了多少文件?

import json
import pandas as pd


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

这是上传文件的方式。代码很好,因为当我将文件分成 100 份时,我可以一份一份上传。但是有没有办法添加一个进度条,以便我可以一次上传文件并查看上传进度?

PS。我没有考虑gui,我有tqdm进度条。我在想这样的事情,这样我就可以在控制台中看到进度

4

1 回答 1

0

如果问题是关于 GUI,那么 PySimpleGUI 允许轻松使用依赖于 Tk、Wx 或 Qt 框架的进度条。这适用于 Linux / Windows。

他们食谱中的例子:

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()

我使用这种进度条并将我的上传功能放在一个单独的线程中,这样 UI 就不会阻塞。

于 2020-08-21T09:30:26.137 回答