background preloader

Style Guide for Python Code

Style Guide for Python Code
Code should be written in a way that does not disadvantage other implementations of Python (PyPy, Jython, IronPython, Cython, Psyco, and such).For example, do not rely on CPython's efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b. This optimization is fragile even in CPython (it only works for some types) and isn't present at all in implementations that don't use refcounting. In performance sensitive parts of the library, the ''.join() form should be used instead. This will ensure that concatenation occurs in linear time across various implementations.Comparisons to singletons like None should always be done with is or is not, never the equality operators.Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context!

http://legacy.python.org/dev/peps/pep-0008/

Related:  Programming in Good StyleTUTORIELS, COURS etcLanguages

The Zen of Python Abstract Long time Pythoneer Tim Peters succinctly channels the BDFL's guiding principles for Python's design into 20 aphorisms, only 19 of which have been written down. The Zen of Python Beautiful is better than ugly. Google Python Style Guide No whitespace inside parentheses, brackets or braces. No whitespace before a comma, semicolon, or colon. Do use whitespace after a comma, semicolon, or colon except at the end of the line. Yes: if x == 4: print x, y x, y = y, x No: if x == 4 : print x , y x , y = y , x TextBlob: Simplified Text Processing — TextBlob 0.9.0-dev documentation Release v0.8.4. (Changelog) TextBlob is a Python (2 and 3) library for processing textual data. It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more. TextBlob stands on the giant shoulders of NLTK and pattern, and plays nicely with both. Features

Be careful with exec and eval in Python written on Tuesday, February 1, 2011 One of the perceived features of a dynamic programming language like Python is the ability to execute code from a string. In fact many people are under the impression that this is the main difference between something like Python and C#. That might have been true when the people compared Python to things like C. It's certainly not a necessarily a feature of the language itself. For instance Mono implements the compiler as a service and you can compile C# code at runtime, just like Python compiles code at runtime.

Popular Python recipes Welcome, guest | Sign In | My Account | Store | Cart ActiveState Code » Recipes Add a Recipe Languages Tags Authors Sets The Principles of Good Programming Heron-Centric: Ruminations of a Language DesignerThe Principles of Good Programmingby Christopher DigginsJuly 24, 2011 Today's post is a lightly edited repost from my blog at The Area, a web-site dedicated to users of Autodesk media and entertainment products. I came up with this list of principles to help with a recent C# training I gave, and I thought that members of the Artima.com community could appreciate these principles and have some interesting insights to share.

Extensible Markup Language (XML) 1.0 (Fifth Edition) 2 Documents [Definition: A data object is an XML document if it is well-formed, as defined in this specification. In addition, the XML document is valid if it meets certain further constraints.] Command-line syntax: some basic concepts I’ve been reading about parsers for command-line arguments lately, for example Plac. And, as Michele Simionato says: There is no want of command line arguments parsers in the Python world. The Python Standard Library — Python v2.7.1 documentation While The Python Language Reference describes the exact syntax and semantics of the Python language, this library reference manual describes the standard library that is distributed with Python. It also describes some of the optional components that are commonly included in Python distributions. Python’s standard library is very extensive, offering a wide range of facilities as indicated by the long table of contents listed below. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming.

Log message style guide Created 9 December 2002, last updated 6 February 2003 One of the fit-and-finish issues all systems developers need to address is the text of log messages. This is a log message style guide. Once your product ships, it will be in customers' hands. They will run it on their machines. You won't be around, and neither will your debugger. Python Programming/Creating Python Programs Welcome to Python! This tutorial will show you how to start writing programs. Python programs are nothing more than text files, and they may be edited with a standard text editor program.[1] What text editor you use will probably depend on your operating system: any text editor can create Python programs. It is easier to use a text editor that includes Python syntax highlighting, however. Hello, World!

How To Use Linux epoll with Python Contents Introduction As of version 2.6, Python includes an API for accessing the Linux epoll library. This article uses Python 3 examples to briefly demonstrate the API. The Python Tutorial — Python v2.7.1 documentation Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, and may be freely distributed.

Related:  PythonPythonPythonPythonProgramacionPythonPython for lifePython