Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Write Better Python Cleaner Code PEP 8

How do you get style errors displayed on Workspace console?

For example, for me python badpep8.py simply runs, it doesn't display any errors so I was wondering is it like some secret key combination you're pressing or something in the settings that let's you see python style errors pointed for you when running the script?

Yeah, it just gives me output and that's all.

3 Answers

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You can also run pep8 <myscript.py> on the command line (outside of the Python shell) and you'll see syntax errors.

that's fair, thx for tip

I actually managed to solve this myself. You have to use

import pep8
checker = pep8.Checker('badpep8.py')

in code to like see it... Thx for checking, tho


An alternative would be to use a PEP8-aware text editor or IDE (Integrated Development Editor). In such an editor, all the deviations from the PEP8 recommendations are highlighted and easy to spot and fix. Plus, the IDE may also provide an auto-fix option so you don't have to apply the modifications manually.

Personally, I am a big fan of the JetBrains family of products (I have no affiliation with those guys, I'm just a happy customer). You can use either IntelliJ Ultimate and install the python plugin (this option costs some money, but in my case, my employer payed for it) or you can use the PyCharm sub-product which I now see has a free community edition. (https://www.jetbrains.com/pycharm/download/)

Another advantage of using an IDE is that you have access to the debugger directly from you editor. You can visually inspect the breakpoints and stackframe, step through the code and query variables etc. from the IDE itself.

That's, my friends, is called technology! Thx for the insight, sounds like a good use of software indeed.

I'd give you best answer, but I wouldn't feel good taking it away from Kenneth)