I want the user to open a file, the file name is passed to a function that uses the file for saving some data. I am using PyQt5 getOpenFileName for this:
fileName, _ = QFileDialog.getOpenFileName(None, "Open Data File")
But, I receive this error message: "Process finished with exit code -1073740791 (0xC0000409)". I am using python 3.7.1 and pyqt 5.9.2. My question is how I can fix this error.
Edit: Here is a sample code:
import pandas as pd
import csv
from PyQt5.QtWidgets import QFileDialog
import os
def saveSubjectList(FileNamePath,subjectList):
columns = list(subjectList[0].__dict__.keys())
vals = []
for iSub in range(len(subjectList)):
valsSub = subjectList[iSub].__dict__.values()
vals.append(valsSub)
subject_pd = pd.DataFrame(vals, columns=columns)
subject_pd.to_csv(FileNamePath)
def loadSubjectList(FileNamePath):
csvFile = open(FileNamePath, 'r')
csvFileArray = []
for row in csv.reader(csvFile):
csvFileArray.append(row[1:])
keys = csvFileArray[0]
subList = []
for sub in csvFileArray[1:]:
subject1 = Subject(sub[0])
for val, key in zip(sub, keys):
setattr(subject1, key, val)
subList.append(subject1)
for item in range(len(subList)):
print(subList[item].__dict__)
class Subject:
def __init__(self, Id):
self.Id = Id
self.Name = ""
self.FrameNumberList = []
self.Color = [0, 1, 0]
if __name__ == '__main__':
subjectList = []
for i in range(2):
subject1 = Subject(i)
subject1.Name = "Subject" + str(i)
subject1.FrameNumberList = [i, 10, 23, 23]
subjectList.append(subject1)
FileNamePath = os.getcwd()
fileName = 'New'
fileNameSuffix = 'csv'
csvPathAndName = os.path.join(FileNamePath, fileName + '.' +
fileNameSuffix)
saveSubjectList(csvPathAndName, subjectList)
loadSubjectList(csvPathAndName)
This is the initial code without getOpenFileName, which works fine. Then I removed the lines from FileNamePath= os.getcwd to csvPathAndName=..., and replaced it with:
csvPathAndName, _ = QFileDialog.getOpenFileName(None, "Open Data File")
because I want the user to be able to create or select the file from anywhere in the computer, but then I get the error.
User contributions licensed under CC BY-SA 3.0