I am working on a project to run PEP8 style check on local projects. I’ve tried to use the subprocess method and I am able to get the generated terminal output of the tips to improve style and save it to a string.
My code to generate the PEP8 style is as below:
def run_pep8_style(target):
pep_tips = subprocess.Popen("python pep8.py --ignore=E111,E501 --filename=*.py " + target, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
tips = pep_tips.communicate()[0]
print "Style: "
print tips
However, I have tried to generate the count using the same subprocess method and store but I am unsuccessful of doing it. The terminal display the output but it is not captured into the string variable.
def run_pep8_count(target):
pep_tips = subprocess.Popen("python pep8.py --ignore=E111,E501 --count -qq --filename=*.py " + target, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
tips = pep_tips.communicate()[0]
print "Count: "
print tips
The strange thing is that I am able to store the list of styles from terminal text into a string variable but it returns none when I try to capture the PEP8 count. Is the terminal output of the count differs from the list of styles? I am a novice to Python programming so any help would be appreciated. Thanks.