Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QtWidgets.QFileDialog.getOpenFileName returns a Tuple

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]

I want filename = {str}'C:/.././.../format.csv'

not filename = <class 'tuple'>: ('C:/.././.../format.csv', '(*.csv)')

like image 610
tisaconundrum Avatar asked Apr 20 '17 02:04

tisaconundrum


1 Answers

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 is a string and the (*.csv) gets discarded in the _filter variable

like image 105
tisaconundrum Avatar answered Oct 21 '22 19:10

tisaconundrum