While solving some exercises from the "Impractical Python Projects" book I've encountered this error:
myconfig.pylintrc:6:1: E0001: Parsing failed: 'cannot assign to expression here. Maybe you meant '==' instead of '='? (<unknown>, line 6)' (syntax-error)
The error occurs while analyzing my code with pylint but doesn't occur while running it in the console. No errors occur at runtime.
This is my solution:
"""Translate words from english to Pig Latin."""
english_vowels = ['a', 'e', 'i', 'o', 'u', 'y']
def main():
"""Take the words as input and return their Pig Latin equivalents."""
print('Welcome to the Pig Latin translator.\n')
while True:
user_word = input('Please enter your own word to get the equivalent in Pig Latin:\n')
if user_word[0].lower() in english_vowels:
print(user_word + 'way')
else:
print((user_word[1:] + user_word[0].lower()) + 'ay')
try_again = input('Try again? Press enter or else press n to quit:\n')
if try_again.lower() == 'n':
break
if __name__ == '__main__':
main()
myconfig.pylintrc is the same as standard.
I've tried moving the variable assignments in and out of the main function or the while loop and I still get this error.
The normal output of pylint
shows the file in error, such as:
pax:/mnt/c/Users/Pax/wsl> cat myprog.py
def myfunc(x):
pass
pax:/mnt/c/Users/Pax/wsl> pylint myprog.py
************* Module myprog
myprog.py:1:1: W0613: Unused argument 'x' (unused-argument)
So it looks like you're trying to run pylint over the file myconfig.pylintrc
, given that it's showing it as the name:
myconfig.pylintrc:6:1: E0001: Parsing fail ...
That's not really a good idea since pylint
is meant to catch issues with Python source, not with its own config files :-) I suspect what you're doing is something like pylint *
rather than pylint *.py
or pylint .
(1).
As way of support for this hypotheses, here's what I see when I run pylint
over my own pylintrc
:
************* Module pylintrc
pylintrc:32:27: E0001: Parsing failed:
'invalid decimal literal (<unknown>, line 32)' (syntax-error)
(1) As an aside, you would normally run pylint
and give it the directories you want to check, since it's quite capable of recursing through those directories and finding Python source code.
If you give it explicit files to check, your testing scripts are going to become rather large as you add more and more files (my own pet project has about forty files, the project we're doing at work has many hundreds).