-1

I started coding a few weeks ago.

I want to do a function to clean some data in Python and I want to send it to coworkers use. I used Qt5 to make an interface but I have some troubles to finish it.

First of all I'm creating a function to open the file, creating a variable to recieve this dateframe (csv).

After I have created another function, called "cleaner" to clean my data. But, before start coding the script to clean the data, I tried to print the dataframe just to see what happened. But when ask to print it, I got a boolean character, and no the dataframe I want. Like "False".

Console shows me it

from interpy import *
import resource
from PyQt5 import QtCore, QtGui, QtWidgets
import pandas as pd
import numpy as np
import csv
from PyQt5.QtWidgets import QDialog, QPushButton, QLabel,QFileDialog,QVBoxLayout
def main(ui):  
    def browseFile(self):
        filename = QtWidgets.QFileDialog.getOpenFileName(None, 'Open File', '*.csv')
    ui.pushButton_arquivo.clicked.connect(browseFile)
    def cleaner(filename):
        print(filename)
    ui.pushButton_Submit.clicked.connect(cleaner)```
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

I believe you are getting False because you are not passing in the filename argument in cleaner. What if you tried this:

def main(ui):  
    def browseFile(self):
        self.filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open File', '*.csv')
    ui.pushButton_arquivo.clicked.connect(browseFile)
    def cleaner(self):
        print(self.filename)
    ui.pushButton_Submit.clicked.connect(cleaner)
irahorecka
  • 1,447
  • 8
  • 25
  • Ira H. I tried but it didn't work. There was this error. File "C:\Users\joao_\Desktop\data\programa.py", line 19, in cleaner print(self.filename) AttributeError: 'bool' object has no attribute 'filename' – Joo Batista Fernandes de Sousa Jul 12 '20 at 05:28
  • Ok, if you print ```self.filename``` right after the ```QFileDialog```, does it return ```False```? – irahorecka Jul 12 '20 at 05:36
  • yes. but when I tried putting '''filename=QtWidgets... print(filename)''' it returned me "runfile('C:/Users/joao_/Desktop/data/programa.py', wdir='C:/Users/joao_/Desktop/data') ('C:/Users/joao_/Downloads/responses (7).csv', '*.csv')" But don't know what to do with it too. – Joo Batista Fernandes de Sousa Jul 12 '20 at 05:42
  • Ok, I changed the code above to replace ```.getOpenFileName(None, ...``` to ```.getOpenFileName(self, ...```. Does that help? – irahorecka Jul 12 '20 at 05:44
  • when I tried with "self" it happened: "TypeError: getOpenFileName(parent: QWidget = None, caption: str = '', directory: str = '', filter: str = '', initialFilter: str = '', options: Union[QFileDialog.Options, QFileDialog.Option] = 0): argument 1 has unexpected type 'bool'" – Joo Batista Fernandes de Sousa Jul 12 '20 at 05:45
  • perhaps pass ```self``` as the first argument in ```main```? – irahorecka Jul 12 '20 at 05:51
  • it returned : NameError: name 'self' is not defined – Joo Batista Fernandes de Sousa Jul 12 '20 at 05:59