Everyday, I am learning new things about this awesome language. One amongst the great things it offers is its readability and how it is ingrained in its syntax. It really makes newbies write readable code. This post is about how to know whether your code is PEP8 compliant. PEP8 is the standard code styling guide followed by python developers worldwide.
- Install the command-line program pep8
$ pip install pep8
- Execute it for the python file, you want to check, to get the code violations. E.g.
$ pep8 test.py
test.py:7:1: W191 indentation contains tabs
test.py:9:1: W191 indentation contains tabs
test.py:10:1: W191 indentation contains tabs
test.py:14:80: E501 line too long (91 > 79 characters)
That’s it! Its as simple as that (simplicity – another great feature of python). You can run it on all of your files together (or on a series of files) :
$ pep8 *.py
Disadvantage: It will give a long list of violations if you are new to python. I recommend running it after every python file you write. Its more manageable that way. Once you are experienced enough, then the above technique will be helpful since the number of violations would be lesser.
Python Guide: Code Style
Here is a summary (read: notes) on the talk given by John Krumm and three other researchers from Microsoft Research back in 2007.
This video gives a good overview about the things which make up a great talk. The Q&A at the end also has a good set of points which are beneficial. It is given by four researchers including John; each speak for approx. 10 minutes. Target audience is a group of researchers working at Microsoft. So, its good for experienced researchers too.
John Krumm starts with why is it important to give a good research talk; goes on to talk about what to say, how to say it, how to chair a session (9th minute) and how to end a talk. Important takeaway: practice; make good eye contact. Definitely listen to his talk in this video.
The second speaker (Patrick) talks about the importance of visuals. Important takeaways: use images/demo/videos in the beginning of the talk, use one image per slide to show related work, use images from the paper to explain concept and use visual tricks to emphasize most important things in an image and make sure you have some interesting takeaway to give e.g. something for the audience to think/learn from the talk. If you don’t want to go through his entire talk, skip to the 25th minute; he gives a summary of all the important points.
The third speaker (Rick) (from the 30th minute) talks about visuals from a different perspective. To illustrate, he uses one of his talks from a conference he presented. I skipped the beginning of his talk since I didn’t find anything useful but listen to the Q&A for his session. Some takeaways: acknowledge your collaborators in the first slide. Important thing to note: He is a great speaker. Notice the way he organizes his speech, keeps a balance and the manner in which he speaks.
The fourth speaker (Mary) (from the 45th minute) gives a list of pointers to keep in mind when giving a talk. She starts with the need to have stellar results to talk about, practical implications of the work being presented; she also gives some tips to prepare for rude Q&A (52th minute). Important takeaway: practice! practice! practice!; proper voice projection; good eye contact; be energetic; good body language; good body posture and balance; prepare for the worst – get questions from the people to whom you give your practice talks.
Some key questions from the Q&A at the End: What is the difference between job talk and conference talk? (from 57th minute) When to memorize and when not to? There are other good ones too. So be sure to listen to them.
Lastly, pick up tips from all the speakers – from the way they give this talk on “giving a great talk”! 😀
I am starting a new page “Tutorials” which will list links to introductory articles/explanations which I have found to be very simple and intuitive. It will range from programming languages like Python, R to computer science and math concepts like machine learning, statistics etc. Hope you find them useful!
I am maintaining a page having an assorted collection of advice on research and activities related to it. You will mostly find things on computer science research since that’s what I do but I believe most of the links on general research can be applied in other fields too. So keep a lookout for this […]