Python (programming language)

This is an old revision of this page, as edited by Sam Pointon (talk | contribs) at 14:05, 3 August 2006 (extend lead a bit). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Python is an interpreted programming language created by Guido van Rossum in 1990. Python is fully dynamically typed and uses automatic memory management; it is thus similar to Perl, Ruby, Scheme, Smalltalk, and Tcl. Python is developed as an open source project, managed by the non-profit Python Software Foundation, and is available for free from the project website. Python 2.4.3 was released on March 29, 2006.

Python
ParadigmMulti-paradigm
Designed byGuido van Rossum
DeveloperPython Software Foundation
First appeared1990
Stable release
2.4.3 / March 29, 2006
Typing disciplineStrong, dynamic ("duck")
OSCross-platform
LicensePython Software Foundation License
Websitewww.python.org
Major implementations
CPython, Jython, IronPython, PyPy
Influenced by
ABC, Modula-3, Icon, C, Perl, Lisp, Smalltalk, Tcl
Influenced
Ruby, Boo

Python is notable amongst current popular high-level languages for having a philosophy that emphasises the importance of the programmer over the importance of the computer (so that, for example, code is slower but easier to understand) and for rejecting more arcane language features. Python is often characterised as minimalistic, though this only applies to the core language's syntax and semtantics; the standard libraries provide the language with a large number of additional libraries and extensions.

The de facto standard for the language is the CPython implementation, although there are other implementations available. Miscellaneous parts of the language have formal specifications and standards, but not the language as a whole.

History

Python 1

File:PythonProgLogo.png
Python logo, 1990s-2005

Python was created in the early 1990s by Guido van Rossum at CWI in the Netherlands as a successor of the ABC programming language. van Rossum is Python's principal author, and his continuing central role in deciding the direction of Python is jokingly acknowledged by referring to him as its Benevolent Dictator for Life (BDFL).

The last version released from CWI was Python 1.2. In 1995, Guido continued his work on Python at the Corporation for National Research Initiatives (CNRI) in Reston, Virginia where he released several versions of the software. Python 1.6 was the last of the versions released by CNRI.

Following the release of Python 1.6, and after Guido van Rossum left CNRI to work with commercial software developers, it became clear that the ability to use Python with software available under the GPL was very desirable. CNRI and the Free Software Foundation (FSF) interacted to develop enabling wording changes to the Python's free software license that would make it GPL-compatible. That year, Guido was awarded the FSF Award for the Advancement of Free Software.

Python 1.6.1 is essentially the same as Python 1.6, with a few minor bug fixes, and with the new GPL-compatible license.

Python 2

In 2000, Guido and the Python core development team moved to BeOpen.com to form the BeOpen PythonLabs team. Python 2.0 was the first and only release from BeOpen.com. After Python 2.0 was released by BeOpen.com, Guido van Rossum and the other PythonLabs developers joined Digital Creations.

Python 2.1 was a derivative work of Python 1.6.1, as well as of Python 2.0. Its license was renamed Python Software Foundation License. All intellectual property added, from the time of Python 2.1's alpha release on, is owned by the Python Software Foundation (PSF), a non-profit organization modeled after the Apache Software Foundation.

The future

Python developers have an ongoing discussion of a future version called Python 3.0 (the project is called "Python 3000" or "Py3K") that will break backwards compatibility with the 2.x series in order to repair perceived flaws in the language. The guiding principle is to "reduce feature duplication by removing old ways of doing things". There is no definite schedule for Python 3.0, but a PEP (Python Enhancement Proposal) that details planned changes exists. [1]

Planned changes include:

  • move map, filter and reduce out of the built-in namespace (the rationale being that map and filter are expressed more clearly as list comprehensions, and reduce more clearly as an accumulation loop)
  • add support for optional type declarations
  • unify the str/unicode types, and introduce a separate mutable bytes type
  • convert built-ins to returning iterators (instead of lists), where appropriate
  • remove backwards-compatibility features like classic classes, classic division, string exceptions, implicit relative imports

Usage

The Python programming language is actively used in industry and academia for a wide variety of purposes. Some of the largest projects that utilise Python are the Zope application server and the Mnet and BitTorrent file sharing systems. It is also extensively used by Google. [2]

Syntax

Python was designed to be a highly readable language. It aims toward an uncluttered visual layout, uses English keywords frequently where other languages use punctuation, and has notably fewer syntactic constructions than many structured languages such as C, Perl, or Pascal.

Indentation

Python uses indentation, rather than curly braces, to delimit blocks. An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.

Control structures and statements

Python's statements include:

  • if statement, for conditionally executing blocks of code, along with else and elif (a contraction of else-if).
  • The while statement runs a block of code until a condition is False.
  • for loops iterate over an iterable, capturing each element to a local variable for use by the attached block.
  • class statements execute a block of code and attach its local namespace to a class, for use in object oriented programming.
  • def defines a function.

Each statement has its own semantics: for example, the def statement does not execute its block immediately, unlike most other statements.

Standard Python does not support continuations, and according to Guido van Rossum, never will. However, better support for coroutine-like functionality is planned, by extending Python's generators [3].

Type system

Python espouses duck typing, also known as latent typing. Type constraints are not checked at compile time; rather, operations on an object may fail, signifying that the given object is not of a suitable type. Despite not enforcing static typing, Python is strongly typed, forbidding operations which make little sense (for example, adding a number to a string).

Fundamental datatypes

Python includes a number of different datatypes. Amongst the most used are:

This list is not exhaustive; there are many other types provided by Python - these are merely some of the most commonly used.

Other features

The standard Python interpreter also supports an interactive mode in which it acts as a kind of shell: expressions can be entered one at a time, and the result of their evaluation is seen immediately. This is a boon for those learning the language and experienced developers alike: snippets of code can be tested in interactive mode before integrating them into a proper program. As well, the Python shell is often used to interactively perform system tasks, such as modifying files.

Implementations

The mainstream Python implementation, also known as CPython, is written in C, and is distributed with a large standard library written in a mixture of C and Python. CPython ships for a large number of supported platforms (see below) and can be ported to other platforms, most readily to POSIX (Unix-like) systems.

There are two other major implementations, Jython for the Java environment, and IronPython for the .NET and Mono environment. PyPy is an experimental self-hosting implementation of Python, in Python, that can output a variety of types of bytecode and object code.

CPython supported platforms

The most popular (and therefore best maintained) platforms Python runs on are Linux, BSD, Mac OS X, Solaris, and Microsoft Windows.

Unix-like

Desktop OSes

Special and embedded

Mainframe and other

Python was originally developed as a scripting language for the Amoeba operating system capable of making system calls; however, that version is no longer maintained.

Many third-party libraries for Python (and even some first-party ones) are only available on Windows, Linux, BSD, and Mac OS X.

Standard library

 
Python comes with "batteries included"

Python has a large standard library, which makes it well suited to many tasks. This comes from a so-called "batteries included" philosophy for Python modules. The modules of the standard library can be augmented with custom modules written in either C or Python. The standard library is particularly well tailored to writing Internet-facing applications, with a large number of standard formats and protocols (such as MIME and HTTP) supported. Modules for creating graphical user interfaces, connecting to relational databases, arithmetic with arbitrarily precise decimals, and manipulating regular expressions are also included. Python also includes a unit testing framework for creating exhaustive test suites.

The standard library is one of Python's greatest strengths. The bulk of it is cross-platform compatible, meaning that even heavily leveraged Python programs can often run on Unix, Windows, Macintosh, and other platforms without change.

It is currently being debated whether or not third-party but open source Python modules such as Twisted, NumPy, or wxPython should be included in the standard library, in accordance with the batteries included philosophy.

Programming philosophy

Multiple paradigms

Python is a multi-paradigm language. This means that, rather than forcing programers to adopt a particular style of programming, it permits several styles: Object orientation, structured programming, functional programming, and aspect-oriented programming are all supported. Many other paradigms are supported using extensions, such as pyDBC and Contracts for Python which allow Design by Contract. Python is dynamically type-checked and uses garbage collection for memory management. An important feature of Python is dynamic name resolution, which binds method and variable names during program execution.

Another target of the language's design is ease of extensibility. New built-in modules are easily written in C or C++. Python can also be used as an extension language for existing modules and applications that need a programmable interface.

Though the design of Python is somewhat hostile to functional programming (no tail-call elimination or good support for anonymous closures) and the Lisp tradition, there are significant parallels between the philosophy of Python and that of minimalist Lisp-family languages such as Scheme. Many past Lisp programmers have found Python appealing for this reason.

Minimalism

While offering choice in coding methodology, Python's designers reject exuberant syntax, such as in Perl, in favor of a sparser, less cluttered one. As with Perl, Python's developers expressly promote a particular "culture" or ideology based on what they want the language to be, favoring language forms they see as "beautiful", "explicit" and "simple". For the most part, Perl and Python users differ in their interpretation of these terms and how they are best implemented (see TIMTOWTDI and Python philosophy).

Culture

Neologisms

A common neologism in the Python community is pythonic, which can have a wide range of meanings related to program style. To say that a piece of code is pythonic is to say that it uses Python idioms well; that it is natural or shows fluency in the language. Likewise, to say of an interface or language feature that it is pythonic is to say that it works well with Python idioms; that its use meshes well with the rest of the language.

In contrast, a mark of unpythonic code is that it attempts to "write C++ (or Lisp, or Perl) code in Python"—that is, provides a rough transcription rather than an idiomatic translation of forms from another language. The concept of pythonicness is tightly bound to Python's minimalistic philosophy of readability - unreadable code or incomprehensible idioms are unpythonic.

Users and admirers of Python—most especially those considered knowledgeable or experienced—are often referred to as Pythonists, Pythonistas, and Pythoneers.

Package naming

The prefix Py- can be used to show that something is related to Python. Examples of the use of this prefix in names of Python applications or libraries include Pygame, a binding of SDL to Python (commonly used to create games), PyUI, a GUI encoded entirely in Python, and PySol, a series of solitaire card games programmed in Python.

Humour

Another important goal of the Python developers is making Python fun to use. This is reflected in the origin of the name (after the television series Monty Python's Flying Circus), in the common practice of using Monty Python references in example code, and in an occasionally playful approach to tutorials and reference materials. For example, the metasyntactic variables often used in Python literature are spam and eggs, instead of the traditional foo and bar.

See also

References

Books

Journals

  • Py, "The Python Online Technical Journal".

Resources

Template:Link FA