0

First of all, I'm a beginner, so any impovement you suggest is really appreciated. Using PyQt5 there is a button which loads up data with np.loadtxt. (It's unpacked into two arrays, because it's x-y data). What I'm trying to achieve is accessing (or storing) that data globally, so later on I can use it in other functions, for example Fourier transform it.

I've already tried to append them into a global np.array defined independently at the top, and also tried the tempfile module, but none of them worked correctly. Here is the function which is called upon clicking the button:

def referenceArmClicked(self):
        options = QFileDialog.Options()
        referenceName, _ = QFileDialog.getOpenFileName(None,"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
        try:
            if referenceName:
                refX, refY= np.loadtxt(referenceName, usecols=(0,1), unpack = True, delimiter =',')

        except: 
            pass #it's just here to simplify the problem, I know it's a bad thing

If I put self.refX and self.refY instead of refX and refY, I need to pass it to the function as arguments:

def referenceArmClicked(self, self.refX, self.refY)

And this is when I connect the function to the button:

self.iReferenceArm.clicked.connect(self.referenceArmClicked)

.. and it doesn't work, and I'm stuck.

The desired output should look something like this: np.array([refX, refY]) All I've got sor far are empty arrays.

Péter Leéh
  • 2,069
  • 2
  • 10
  • 23
  • if you need in functions in the same class then use `self.` - `self.refx`, `self.refY` – furas Jul 07 '19 at 18:38
  • `except: pass` can be devil. Maybe you have error but you don't know it. Maybe all your problem can be resolved with this error message. You should at least display it `except Exception as ex: print(ex)` – furas Jul 07 '19 at 18:41
  • The except: pass is just there is simplify my question, but thank you. – Péter Leéh Jul 07 '19 at 18:47

0 Answers0