I have a general question about Python3.
For a while now Ive been exploring the various uses of this language.
The project im currently exploring is this project to create a browser using PyQt5. (Yes, im trying to steal chrome’s throne for the browser that uses the most processing power.) The basic code structure is relatively simple, but it relies on absolute imports as a pose to just listing off the relative imports used in the program.
from PyQt5.QtCore import * from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtWebEngineWidgets import * import sys class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow,self).__init__(*args, **kwargs) self.browser = QWebEngineView() self.browser.setUrl(QUrl("http://www.google.com")) self.setCentralWidget(self.browser) self.show() app = QApplication(sys.argv) window = MainWindow() app.exec_()
Before I tried to execute the script from my IDE, I copied the requirements file in the guide and installed it with
pip install -r requirements.txt. All dependencies installed properly with no errors. The contents of requirements.txt are as follows:
However, my IDE highlighted several parts of the code with the following message:
[pyflakes] "from PyQt5.QtCore import *" used; unable to detect undefined names.
Now, I have consulted other threads on Stack Exchange to try and solve the issue. Like this one.
As Blender says on this thread:
Your IDE is complaining, not Python. When you do from simple import *, you import everything exposed by simple. This is typically not recommended because it pollutes the global namespace and may implicitly overwrite an existing object.
He also indicates that the error can be suppressed in the IDE by commenting the import line with NOQA like this
from PyQt5 import * # NOQA and I did try this with repl.it but it didn’t work and the script still wouldn’t execute and gave no error.
So, from what I can gather, the only solution is to go into the modules and write out each relative import manually one by one. Im happy with this, its best practice, I can work with it. I just need to learn a system / find a program that can allow me to reverse engineer the code I have, see which parts of the module its referencing, and get a list of what’s used, to list it.
This is of course, a bit of a Paradox, and I was wondering how you’d go about doing this when you’re not the one who’s wrote the code and have no prior knowledge of the module? I considered the brute force option, just write every single option manually and effectively do an absolute import that way which should hopefully negate the undefined name error, but even just the QtCore aspect of the module is absolutely massive.
I also wouldn’t be learning anything, so any assistance is greatly appreciated. I understand i don’t have the ideal development platform and I can move to a Linux VM but im trying to avoid doing so in favor of having all my code in one place.
Source: Python-3x Questions