NameError: name 'self' is not defined
-
wrote on 3 Jan 2021, 17:39 last edited by
This is the code for opening .tif on a PyQT window:
import sys from PyQt5.QtWidgets import QApplication, QMainWindow app = QApplication(sys.argv) window = QMainWindow() window.show() def getFrame(self): fp = r'/home/UbuntuUser/Desktop/UAV.tif' self.img = cv2.imdecode(np.fromfile(fp, dtype=np.uint8), cv2.IMREAD_UNCHANGED) print(self.img) self.getFrame() # Start the event loop. app.exec_()
Why do I get this error??
Traceback (most recent call last): File "mycode.py", line 14, in <module> self.getFrame() NameError: name 'self' is not defined
-
@john_hobbyist said in NameError: name 'self' is not defined:
Why do I get this error??
Because you try to call a function but you're not in a class so self is not available.. Python basics.
-
wrote on 3 Jan 2021, 18:23 last edited by
Because I cannot understand what to do with the 'self' I removed it and when running the code, instead of getting an image, I get a white image. Is this due to the 'self', or it is because of the rest of the code?
-
Hi,
From your code, at no point are you showing any image on anything.
You are loading an image mixing numpy and OpenCV.
-
wrote on 8 Jan 2021, 11:08 last edited by hachbani 1 Aug 2021, 11:08
Not here for a solution to your problem, but I advise you to watch this video
-
Because I cannot understand what to do with the 'self' I removed it and when running the code, instead of getting an image, I get a white image. Is this due to the 'self', or it is because of the rest of the code?
wrote on 8 Jan 2021, 11:10 last edited by@john_hobbyist said in NameError: name 'self' is not defined:
Because I cannot understand what to do with the 'self' I removed it
I would suggest you to learn some Python basics, like class ==> https://www.geeksforgeeks.org/self-in-python-class/
1/6