4 ms·
A bit of a nitpick, but it would be nice if the facts were PEP8 compliant so they encouraged good code style as well as showing off Python features.
by kisielk 15y ago
A bit of a nitpick, but it would be nice if the facts were PEP8 compliant so they encouraged good code style as well as showing off Python features.
- ronreiter 15y agoi'm doing my best to moderate them, but you know how it works...
- drx 15y agoTry https://github.com/jcrocholl/pep8 https://github.com/jcrocholl/pep8 You could show the output of this to the submitter (somewhat bad -- barrier to submission) or flag them yourself so you can correct them occasionally. Examples: $ pep8 optparse.py optparse.py:69:11: E401 multiple imports on one line optparse.py:77:1: E302 expected 2 blank lines, found 1 optparse.py:88:5: E301 expected 1 blank line, found 0 $ pep8 --show-source --show-pep8 testsuite/E111.py testsuite/E111.py:2:3: E111 indentation is not a multiple of four print x ^ Use 4 spaces per indentation level. For really old code that you don't want to mess up, you can continue to use 8-space tabs.
- mapleoin 15y agoSo then you could add something like a 'report' button to allow users to say what they think is mistaken.
- shenberg 15y agoI'm not sure I agree - if it helps get the point of the snippet across more succinctly, it's worth breaking the guidelines.
- cbo 15y agoNot just PEP8-compliant. Some of these are just plain bad. The first one I was greeted with when I opened the site was: > print eval('+'.join(map(str, [1, 1]))) If I ever saw this in production code, I would lose my mind. It's the kind of one-liner I'd expect to find in an obfuscated code competition. It's not intuitively understood, shows a lack of basic Python functionality (the builtin sum() function), and most of all, it's SLOW. As in, 54 times slower than a simple sum -- tested on xrange(1,10) -- on my development Macbook Pro. That said, clicking through some other examples, there are a lot of great Python examples on this site. Just beware of some of them, and always make sure you test new code yourself.