'How does one get a list of all possible errors in a python file?
Looking through pycharm, I can see that they are able to recognize possible errors. How would I do that with Python? Here is an example:
if I have a file named, for example, something.py
de foo(bar: str) -> str:
printbar)
fo (2)
how would I make it so that it finds that de doesn't exist in the python file, catch the error and log it in a .txt file and continue with the code but then find that printbar doesn't exist, log it, etc, etc.
This is the code I currently have:
class Sherlock:
def __init__(self, file):
self.file = file
def catch(self):
x = ''
with open(self.file, 'r') as f:
for lines in f:
x += lines
print(x)
but I do not know where to go from there. Any answers would be much appreciated.
Solution 1:[1]
What you are trying to do is write a linter, which is a large and complex piece of software that cannot be done with a small Python class. Assuming that you do not want to spend months or years writing your own linter from scratch, you should check out linters that others have written for Python such as pylint.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | adang1345 |
