>>> pip install pylint
>>> pylint --long-help
파이참에서 Pylint 플러그인으로 추가
Output
Output status code
사용 팁
# pylint: disable=C0304
와 같이 추가하면 필요없는 경고는 끌 수 있습니다. pylint -reports=n 파일명.py
-rn
으로 줄여 쓸 수 있다.pylint --max-line-length=79 파일명.py
파일경로/pylint -rn --max-line-length=79 --generate-rcfile > 설정파일명.pylintrc
pylint --rcfile 설정파일명.pylintrc 파일명
import string
shift = 3
choice = input("would you like to encode or decode?")
word = input("Please enter text")
letters = string.ascii_letters + string.punctuation + string.digits
encoded = ''
if choice == "encode":
for letter in word:
if letter == ' ':
encoded = encoded + ' '
else:
x = letters.index(letter) + shift
encoded=encoded + letters[x]
if choice == "decode":
for letter in word:
if letter == ' ':
encoded = encoded + ' '
else:
x = letters.index(letter) - shift
encoded = encoded + letters[x]
print(encoded)
pylint lint.py
************* Module lint
lint.py:14:19: C0326: Exactly one space required around assignment
encoded=encoded + letters[x]
^ (bad-whitespace)
lint.py:24:0: C0304: Final newline missing (missing-final-newline)
lint.py:1:0: C0111: Missing module docstring (missing-docstring)
lint.py:3:0: C0103: Constant name "shift" doesn't conform to UPPER_CASE naming style (invalid-name)
lint.py:4:0: C0103: Constant name "choice" doesn't conform to UPPER_CASE naming style (invalid-name)
lint.py:5:0: C0103: Constant name "word" doesn't conform to UPPER_CASE naming style (invalid-name)
lint.py:6:0: C0103: Constant name "letters" doesn't conform to UPPER_CASE naming style (invalid-name)
lint.py:7:0: C0103: Constant name "encoded" doesn't conform to UPPER_CASE naming style (invalid-name)
-------------------------------------------------------------------
Your code has been rated at 4.74/10 (previous run: -0.53/10, +5.26)
configuration file
포함하거나 제외하고 싶은 분석 결과를 임의로 설정할 수 있다.
실행 파일에 위치시키거나, pylint --rcfile 설정파일명.pylintrc 파일명
을 이용하여 실행하거나, pycharm 플러그인에 등록하라!
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/.pylintrc 에서 긁어쓰자.
Message emitted:
Redefining name %r from outer scope (line %s)
Description:
변수 이름이 "외부 범위 혹은 except handler 에 정의된 이름"을 숨기는 경우 사용
Consider iterating the dictionary directly instead of calling .keys()
FRUITS = {"apple": 1, "pear": 5, "peach": 10}
for fruit in FRUITS.keys(): # [consider-iterating-dictionary]
print(fruit)
FRUITS = {"apple": 1, "pear": 5, "peach": 10}
for fruit in FRUITS:
print(fruit)
Wildcard import %s
from module import *
is detected.from abc import * # [wildcard-import]
# Either import module or
# only import required objects from module.
import abc
from abc import ABC, abstractmethod
Iterated dict '%s' is being modified inside for loop body, iterate through a copy of it instead.
fruits = {"apple": 1, "orange": 2, "mango": 3}
i = 0
for fruit in fruits:
fruits["apple"] = i # [modified-iterating-dict]
i += 1
fruits = {"apple": 1, "orange": 2, "mango": 3}
i = 0
for fruit in fruits.copy():
fruits["apple"] = i
i += 1
항상 감사합니다