Is it possible I get assistance here? My function saves a file with a space after every row, also the column headers are not saved. Here is the function.
def download_results(self):
    try:
        path = QFileDialog.getSaveFileName(MainWindow, 'Save results', os.getenv('HOME'), 'CSV(*.csv)')
        if path[0] != '':
            with open(path[0], 'w') as csv_file:
                writer = csv.writer (csv_file, dialect = 'excel', delimiter = ',')
                for row in range(self.analysis_table.rowCount()):
                    row_data = []
                    for column in range(self.analysis_table.columnCount()):
                        item = self.analysis_table.item(row, column)
                        if item is not None:
                            row_data.append(item.text())
                        else:
                            row_data.append('')
                    writer.writerow(row_data)
        QMessageBox.information(MainWindow,"Success","Succeeded")
    except:
        QMessageBox.warning(MainWindow,"Failed","Operation failed.")
 
    