'How do I import a file into my project folder using PyQt5's QFileDialog?

I'm trying to import a csv file into my Python project with PyQt5's QFileDialog. All I need is for it to copy a file from one location and paste it in another yet I can't seem to figure it out.

    def open(self):
        home_dir = str(Path.home())
        fname = QFileDialog.getOpenFileName(self, 'Open file', home_dir)

        # if file selected import into folder
        if fname[0]:
            print(fname)
            with open(fname, 'r') as fobj, open('Data/Inventory.csv', 'wb') as f:
                data = fobj.read()
                df = pd.read_csv(data)
                f.write(df)

So far this is all I have. I had a version before that created a blank file in the desired directory but that's obviously not enough.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source