Can I ask pep8 in python to parse a string instead of a file?

126 Views Asked by At
import pep8

s = """
def a:
    pass

def b:
   pass

"""

pep8.StyleGuide().is_such_method_exists_for_string_?(s)

// and then, get out put as list ?

1

There are 1 best solutions below

1
On BEST ANSWER
import pep8

lines = """
def a:
    pass

def b:
   pass
"""

checker = pep8.Checker(
    lines=lines.strip().splitlines(),
    filename=None,
    show_source=True
)
result = checker.check_all()