問題描述
我最近更新到了 Qt5 for Python 的新版本.在這樣做的過程中,我不得不根據(jù)已經(jīng)發(fā)生的一些顯著變化來更改我的代碼.我想深入了解我創(chuàng)建的這行代碼.這感覺像是一種解決從函數(shù)中獲取 string
而不是 tuple
問題的骯臟方式.(注意行尾的[0]
)
I've recently updated to the new version of Qt5 for Python. In doing so, I've been having to alter my code in accordance to some of the notable changes that have occurred. I wanted to get some insight into this line of code that I've created. It feels like a dirty way of solving the problem of getting a string
instead of a tuple
from the function. (Note the [0]
at the end of the line)
filename = QtWidgets.QFileDialog.getOpenFileName(None, "Open " + key + " Data File", '.', "(*.csv)")[0]
我想要 filename = {str}'C:/.././.../format.csv'
not filename = <class 'tuple'>: ('C:/.././.../format.csv', '(*.csv)')
推薦答案
在查看了一個也正在更新到 Qt5 的存儲庫之后;我發(fā)現(xiàn)他們使用了這樣的一行.
After looking through a repository that was being updated to Qt5 as well; I found they used a line like this.
filename, _filter = QtWidgets.QFileDialog.getOpenFileName(None, "Open " + key + " Data File", '.', "(*.csv)")
filename
是一個字符串,并且 (*.csv) 在 _filter
變量中被丟棄
filename
is a string and the (*.csv) gets discarded in the _filter
variable
這篇關于QtWidgets.QFileDialog.getOpenFileName 返回一個元組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!