Seite 1 von 1

TypeError: setText(self, a0: Optional[str]): argument 1 has unexpected type 'tuple'

Verfasst: Sonntag 16. Juni 2024, 20:59
von DanaScully
Sorry falls das eine peinliche Anfängerfrage ist, bin eine peinliche Anfängerin und brauche mal einen Experten. :-)
Wie fixe ich den Fehler aus dem Betreff?

Im Detail:
--------------------------------------------------------
Traceback (most recent call last):

File c:\users\doher\desktop\asap automatic spectral assignment procedure\asap-qt5\cawin.py:349 in load_predictions
self.lE_predictions_filename.setText(filename)

TypeError: setText(self, a0: Optional[str]): argument 1 has unexpected type 'tuple'
---------------------------------------------------------
Der Code dazu:
345 def load_predictions(self):
346 filename = str(self.lE_predictions_filename.text())
347 if not filename:
348 filename = self.selectFile(title = 'Select file which contains predictions')
349 self.lE_predictions_filename.setText(filename)
350 self.predictions = sa.Predictions(filename)
351 self.predictions.convertUnit('wvn')
352 self.populate_table_predictions()
---------------------------------------------------------
Inhalt des zu ladenden Files predictionshood.cat:

7.8796-99.9900 -4.7324 3 0.0000 3 999991404 1 1 1 0 0 0 0 0
13.7072-99.9900 -3.2799 3 0.0000 3 999991404 1 1 0 1 0 0 0 0
2.1420-99.9900 -4.8925 3 5.7861 3 999991404 1 1 0 0 0 0 0 1
7.8756-99.9900 -4.7450 3 5.7861 3 999991404 1 1 1 1 0 0 0 1
6.3114-99.9900 -4.7577 3 7.3958 3 999991404 1 1 0 1 1 0 1 1
3.7993-99.9900 -4.2234 3 7.3958 5 999991404 2 1 1 0 1 0 1 1
9.4398-99.9900 -4.4220 3 7.3958 5 999991404 2 1 2 1 1 0 1 1
2.6868-99.9900 -5.0080 3 7.9281 5 999991404 2 0 2 1 1 1 0 0
22.0747-99.9900 -3.6859 3 7.9281 5 999991404 2 2 1 0 1 1 0 0
27.8386-99.9900 -2.5180 3 7.9281 5 999991404 2 2 0 1 1 1 0 0
16.3411-99.9900 -2.9831 3 13.6617 5 999991404 2 2 1 0 1 1 1 1
------------------------------------------------------------
Hoffentlich kann mir jemand helfen... :?:

Re: TypeError: setText(self, a0: Optional[str]): argument 1 has unexpected type 'tuple'

Verfasst: Montag 17. Juni 2024, 09:09
von /me
Wir wissen nicht, was self.selectFile ist, aber das liefert offensichtlich ein Tupel statt eines Strings zurück.

Re: TypeError: setText(self, a0: Optional[str]): argument 1 has unexpected type 'tuple'

Verfasst: Montag 17. Juni 2024, 10:12
von __blackjack__
@DanaScully: Wenn ich mal raten müsste führt das irgendwo zu einem Aufruf von so etwas wie `QFileDialog::getOpenFileName()` und der Autor (Du?) dachte das liefert einen `QString`/`str` zurück und hat dabei übersehen, dass da in C++ ein ”out”-Parameter mit in der Parameterliste dieser Methode ist (`selectedFilter`). So etwas kennt Python nicht, darum wird das in ein Tupel mit Rückgaben ”übersetzt”.

Anmerkung am Rande: Der `str()`-Aufruf in Zeile 346 sieht komisch bis überflüssig aus.