background preloader

Neopythonic - Guido's Blog

Neopythonic - Guido's Blog

How not to write Python code – Ikke's blog Lately I’ve been reading some rather unclean Python code. Maybe this is mainly because the author(s) of the code had no in-depth knowledge of the Python language itself, the ‘platform’ delivered with cPython,… Here’s a list of some of the mistakes you should really try to avoid when writing Python code: Some days ago RealNitro pointed me at this list of essential Python readings. “Idiomatic Python” is a must-read, even for experienced Python developers. That’s about it for now, maybe I’ll add some more items to this list later on. If you have some other hints, comments! Posted in Development, Technology. Tagged with Development, python. By Nicolas – February 8, 2008

ajmals PEP 8 -- 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.

PyPy Status Blog Reader - Basshero.org Chemoton § Vitorino Ramos' research notebook PEP 257 -- Docstring Conventions What is a Docstring? A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of that object. All modules should normally have docstrings, and all functions and classes exported by a module should also have docstrings. String literals occurring elsewhere in Python code may also act as documentation. String literals occurring immediately after a simple assignment at the top level of a module, class, or __init__ method are called "attribute docstrings".String literals occurring immediately after another docstring are called "additional docstrings". Please see PEP 258, "Docutils Design Specification" , for a detailed description of attribute and additional docstrings. XXX Mention docstrings of 2.2 properties. For consistency, always use """triple double quotes""" around docstrings. There are two forms of docstrings: one-liners and multi-line docstrings. Multi-line Docstrings

Planet Python Nuitka Home and Blog of Kay Hayen | Nuitka Home and Blog of Kay Hayen

Related: