B.4. Style

Try to comply with PEP8 (http://python.org/dev/peps/pep-0008), even if you don’t plan on sharing your code with others. Your future self will appreciate being able to efficiently read and debug your code. Adding a linter (http://sublimelinter.com) or automatic style corrector (http://packagecontrol.io/packages/Anaconda) to your editor or IDE is the easiest way to get with the PEP8 program.

One additional style convention that can help with natural language processing is how you decide between the two possible quote characters (' and "). Whatever you do, try to be consistent. One thing that can help make your code more readable by professionals is to always use the single-quote (') when defining a string intended for a machine, like regular expressions, tags, and labels. Then you can use double quotes ('"') for natural language corpora intended for human consumption.

What about raw strings ( r'' and r"")? All regular expressions should be single-quoted raw strings like r'match[ ]this', even if they don’t contain backslashes. Docstrings should be triple-quoted raw strings, like r""" This function does NLP """. That way if you ever do add backslashes to your doctests or regular expressions, they will do what you expect.[4]

4

This stack overflow question explains why (https://stackoverflow.com/q/8834916/623735).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset