background preloader

Style Guide for Python Code

This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python [1]. This document and PEP 257 (Docstring Conventions) were adapted from Guido's original Python Style Guide essay, with some additions from Barry's style guide [2]. This style guide evolves over time as additional conventions are identified and past conventions are rendered obsolete by changes in the language itself. Many projects have their own coding style guidelines. In the event of any conflicts, such project-specific guides take precedence for that project. One of Guido's key insights is that code is read much more often than it is written. A style guide is about consistency. However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. Some other good reasons to ignore a particular guideline: Indentation

https://www.python.org/dev/peps/pep-0008/

Related:  PYTHONPythonpython

Supporting Non-ASCII Identifiers This PEP suggests to support non-ASCII letters (such as accented characters, Cyrillic, Greek, Kanji, etc.) in Python identifiers. Python code is written by many people in the world who are not familiar with the English language, or even well-acquainted with the Latin writing system. Such developers often desire to define classes and functions with names in their native languages, rather than having to come up with an (often incorrect) English translation of the concept they want to name. By using identifiers in their native language, code clarity and maintainability of the code among speakers of that language improves.

SLEP009: Keyword-only arguments — Scikit-learn enhancement proposals documentation Abstract¶ This proposal discusses the path to gradually forcing users to pass arguments, or most of them, as keyword arguments only. It talks about the status-quo, and the motivation to introduce the change. It shall cover the pros and cons of the change.

Think Python 2e – Green Tea Press Think Python 2nd Edition by Allen B. Downey This is the second edition of Think Python, which uses Python 3. If you are using Python 2, you might want to use the first edition, which is here. You can buy the second edition at Amazon.com Download Think Python 2e in PDF.

UAX #31: Unicode Identifier and Pattern Syntax Unicode® Standard Annex #31 Summary This annex describes specifications for recommended defaults for the use of Unicode in the definitions of identifiers and in pattern-based syntax. It also supplies guidelines for use of normalization with identifiers. Status This document has been reviewed by Unicode members and other interested parties, and has been approved for publication by the Unicode Consortium. Python: better typed than you think Now, let's try out returns.result library, clearly inspired by Haskell's Either monad and do notation. I'm quite glad someone already implemented it and I didn't have to reinvent the wheel here. So, let's try and rewrite the code using returns.result.Result: 19: from returns.result import safe 20: 21: @safe22: def parse_entry(entry: str) -> Highlight: 23: groups = re.search( 24: r'(?P<title>.*)$\n.*Highlight on Page (?

Le tutoriel Python — Documentation Python 3.8.5 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. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation. The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C).

2. Analyse lexicale — documentation Python 3.6.3 A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer. This chapter describes how the lexical analyzer breaks a file into tokens. Structuring Your Project — The Hitchhiker's Guide to Python By “structure” we mean the decisions you make concerning how your project best meets its objective. We need to consider how to best leverage Python’s features to create clean, effective code. In practical terms, “structure” means making clean code whose logic and dependencies are clear as well as how the files and folders are organized in the filesystem. Which functions should go into which modules?

numpy.linspace — NumPy v1.10 Manual start : scalar The starting value of the sequence. stop : scalar The end value of the sequence, unless endpoint is set to False. Beautiful Soup Documentation — Beautiful Soup 4.9.0 documentation Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work. These instructions illustrate all major features of Beautiful Soup 4, with examples. The Best Python Books for All Skill Levels Just about every year is a good year to be investing in Python learning, whether you are a beginner or an expert. Employment opportunities are opening for Python developers in fields beyond traditional web development. An IBM blog post reports that Python is now the dominant language in many data science and machine learning careers. We charted data from DataScienceCentral to see how well Python is doing in this new field. Here is the result. As you can see, it seems to be doing pretty well.

Related: