Ariranha and Python (programming language): Difference between pages

From Wikipedia, the free encyclopedia
(Difference between pages)
Content deleted Content added
m Removed category "São Paulo state" (using HotCat)
 
Cython is really just a "Python-like" language (and still experimental)... find somewhere more accurate for mention
 
Line 1: Line 1:
{{infobox programming language
{{coord|21|11|16|S|48|47|13|W|scale:30000|display=title}}
| name = Python
{{For|the mamal called ''Ariranha'' in [[Portuguese language|Portuguese]]|Giant Otter}}
| logo = [[Image:Python logo.svg|300px]]
'''Ariranha''' is a city in the state of [[São Paulo (state)|São Paulo]] in [[Brazil]]. The population as of [[2003]] was 8,314 and the area is 133.56 km². The elevation is 595 m.
| paradigm = [[Multi-paradigm programming language|multi-paradigm]]: [[Object-oriented programming|object-oriented]], [[Imperative programming|imperative]], [[Functional programming|functional]]
| year = 1991
| designer = [[Guido van Rossum]]
| developer = [[Python Software Foundation]]
| latest_release_version = 2.6
| latest_release_date = {{release date|mf=yes|2008|10|1}}
| latest_test_version = 3.0rc1
| latest_test_date = {{release date|mf=yes|2008|9|17}}
| typing = [[strong typing|strong]], [[dynamic typing|dynamic]], [[duck typing|duck]]
| implementations = [[CPython]], [[Jython]], [[IronPython]], [[PyPy]]
| dialects = [[Stackless Python]], [[RPython]]
| influenced_by = [[ABC programming language|ABC]], [[ALGOL 68]],<ref>{{cite web |url=http://www.amk.ca/python/writing/gvr-interview |title=Interview with Guido van Rossum|year=1998 |month=July |accessmonthday=29 |accessyear=2007}}</ref> [[C (programming language)|C]], [[Haskell (programming language)|Haskell]], [[Icon programming language|Icon]], [[Lisp programming language|Lisp]], [[Modula-3]], [[Perl]], [[Java (programming language)|Java]]
| influenced = [[Boo programming language|Boo]], [[Groovy (programming language)|Groovy]], [[Ruby programming language|Ruby]], [[Cobra (programming language from Cobra Language LLC)|Cobra]], [[D (programming language)|D]]
| operating_system = [[Cross-platform]]
| license = [[Python Software Foundation License]]
| website = http://www.python.org/
}}
'''Python''' is a general-purpose, [[high-level programming language]].<ref>{{cite web |url= http://www.python.org/doc/faq/general/#what-is-python-good-for|title= What is Python Good For?|accessdate=2008-09-05 |work= General Python FAQ|publisher= Python Foundation}}</ref> Its design philosophy emphasizes programmer productivity and code readability.<ref>{{ cite web | url = http://www.python.org/doc/essays/blurb/ | title = What is Python? Executive Summary | publisher = Python Foundation | work = Python documentation | accessdate = 2007-03-21 }}</ref> Python's core syntax and semantics are [[Minimalism (computing)|minimalistic]], while the [[standard library]] is large and comprehensive. Its use of [[whitespace (computer science)|whitespace]] as block delimiters is unusual among popular programming languages.


Python supports multiple [[programming paradigm]]s (primarily [[Object-oriented programming|object oriented]], [[Imperative programming|imperative]], and [[Functional programming|functional]]) and features a fully [[dynamic type]] system and automatic [[memory management]], similar to [[Perl]], [[Ruby (programming language)|Ruby]], [[Scheme (programming language)|Scheme]], and [[Tcl]]. Like other dynamic languages, Python is often used as a [[scripting language]].
[[Category:Cities, towns and villages in São Paulo State]]


Python was first released by [[Guido van Rossum]] in 1991.<ref name="svn-history">{{ cite web | title = HISTORY | url = http://svn.python.org/view/*checkout*/python/trunk/Misc/HISTORY | work = Python source distribution | publisher = Python Foundation | accessdate = 2007-03-21 }}</ref> The language has an open, community-based development model managed by the non-profit [[Python Software Foundation]], which also maintains the ''[[de facto]]'' standard definition of the language in [[CPython]], the reference implementation.
{{SaoPauloState-geo-stub}}


==History==
[[bpy:আরিরানহা]]
[[Image:PythonProgLogo.png|thumb|Python logo, 1990s-2005]]
[[it:Ariranha]]
Python was conceived in the late 1980s<ref name="venners-interview-pt-1">{{cite web|url = http://www.artima.com/intv/pythonP.html|title = The Making of Python|accessdate = 2007-03-22|publisher = Artima Developer}}</ref> by Guido van Rossum at [[National Research Institute for Mathematics and Computer Science|CWI]] in the Netherlands as a successor to the [[ABC programming language]] capable of [[exception handling]] and interfacing with the [[Amoeba distributed operating system|Amoeba operating system]].<ref name = "faq-created">{{ cite web | url = http://www.python.org/doc/faq/general/#why-was-python-created-in-the-first-place | title = Why was Python created in the first place? | publisher = Python FAQ | accessdate = 2007-03-22}}</ref> Van Rossum is Python's principal author, and his continuing central role in deciding the direction of Python is reflected in the title given him by the Python community, [[Benevolent Dictator For Life|''Benevolent Dictator for Life'' (BDFL)]].
[[no:Ariranha]]

[[pt:Ariranha (São Paulo)]]
===First publication===
[[ro:Ariranha]]
In 1991, van Rossum published the code (labeled version 0.9.0) to alt.sources.<ref name="svn-history" /> Already present at this stage in development were classes with inheritance, exception handling, functions, and the core datatypes of <code>list</code>, <code>dict</code>, <code>str</code> and so on. Also in this initial release was a [[module system]] borrowed from [[Modula-3]]; van Rossum describes the module as "one of Python's major programming units".<ref name="venners-interview-pt-1" /> Python's exception model also resembles Modula-3's, with the addition of an <code>else</code> clause.<ref name = "faq-created" /> In 1994 [news://comp.lang.python comp.lang.python], the primary discussion forum for Python, was formed, marking a milestone in the growth of Python's userbase.
[[vo:Ariranha]]

===Version 1.0===
Python reached version 1.0 in January 1994. The major new features included in this release were the functional programming tools <code>[[lambda calculus|lambda]]</code>, <code>map</code>, <code>filter</code> and <code>[[Fold (higher-order function)|reduce]]</code>. Van Rossum stated that “Python acquired lambda, reduce(), filter() and map(), courtesy of (I believe) a [[Lisp]] hacker who missed them and submitted working patches.”<ref>{{cite web|url = http://www.artima.com/weblogs/viewpost.jsp?thread=98196|title = The fate of reduce() in Python 3000|author = Guido van Rossum|accessdate = 2007-03-22|publisher = Artima Developer}}</ref>

The last version released while van Rossum was at CWI was Python 1.2. In 1995, van Rossum continued his work on Python at the [[Corporation for National Research Initiatives]] (CNRI) in [[Reston, Virginia|Reston]], [[Virginia]] from where he released several versions.

By version 1.4, Python had acquired several new features. Notable among these are the [[Modula-3]] inspired [[keyword argument]]s (which are also similar to [[Common Lisp]]'s keyword arguments), and built-in support for [[complex number]]s. Also included is a basic form of [[data hiding]] by [[name mangling]], though this is easily bypassed.<ref>{{cite web|url=http://www.amk.ca/python/writing/12-14|title=LJ #37: Python 1.4 Update|accessdate=2007-04-29}}</ref>

During van Rossum's stay at CNRI, he launched the [[Computer Programming for Everybody]] (CP4E) initiative, intending to make programming more accessible to more people, with a basic 'literacy' in programming languages, similar to the basic English literacy and mathematics skills required by most employers. Python served a central role in this: because of its focus on clean syntax, it was already suitable, and CP4E's goals bore similarities to its predecessor, ABC. The project was funded by [[DARPA]].<ref>{{cite web|url = http://www.python.org/doc/essays/cp4e.html|author = Guido van Rossum|title = Computer Programming for Everybody|accessdate = 2007-03-22}}</ref> {{As of|2007}}, the CP4E project is inactive, and while Python attempts to be easily learnable and not too arcane in its syntax and semantics, reaching out to non-programmers is not an active concern.<ref>{{cite web|url = http://www.python.org/cp4e/|title = Computer Programming for Everybody|accessdate = 2007-03-22|publisher = Python Software Foundation}}</ref>

===BeOpen===
In 2000, the Python core development team moved to [[BeOpen.com]] to form the BeOpen [[PythonLabs]] team. CNRI requested that a version 1.6 be released, summarizing Python's development up to the point at which the development team left CNRI. Consequently, the release schedules for 1.6 and 2.0 had a significant amount of overlap.<ref name="newin-2.0">{{cite web|url = http://www.amk.ca/python/2.0/|title = What's New in Python 2.0|author = A.M. Kuchling and Moshe Zadka|accessdate = 2007-03-22}}</ref> 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]].

The Python 1.6 release included a new CNRI license that was substantially longer than the CWI license that had been used for earlier releases. The new license included a clause stating that the license was governed by the laws of the [[State of Virginia]]. The [[Free Software Foundation]] argued that the choice-of-law clause was incompatible with the [[GNU GPL]]. BeOpen, CNRI, and the FSF negotiated a change to Python's [[free software license]] that would make it GPL-compatible. 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.<ref name="lib-history">{{cite web|url = http://www.python.org/doc/2.5/lib/node951.html|title = History of the software|work = Python Library Reference|accessdate = 2007-03-22}}</ref>

===Version 2.0===
Python 2.0 introduced [[list comprehension]]s, a feature borrowed from the [[functional programming]] languages [[SETL]] and [[Haskell (programming language)|Haskell]]. Python's syntax for this construct is very similar to Haskell's, apart from Haskell's preference for punctuation characters and Python's preference for alphabetic keywords. Python 2.0 also introduced a [[garbage collection (computer science)|garbage collection]] system capable of collecting reference cycles.<ref name="newin-2.0" />

Python 2.1 was close to Python 1.6.1, as well as Python 2.0. Its license was renamed [[Python Software Foundation License]]. All code, documentation and specifications added, from the time of Python 2.1's alpha release on, is owned by the [[Python Software Foundation]] (PSF), a non-profit organization formed in 2001, modeled after the [[Apache Software Foundation]].<ref name="lib-history" /> The release included a change to the language specification to support nested scopes, like other [[static scoping|statically scoped]] languages.<ref>{{cite web|url = http://www.python.org/dev/peps/pep-0227/|title = Statically Nested Scopes|author = Jeremy Hylton|accessdate = 2007-03-22}}</ref> (The feature was turned off by default, and not required, until Python 2.2.)

A major innovation in Python 2.2 was the unification of Python's types (types written in C), and classes (types written in Python) into one hierarchy. This single unification made Python's object model purely and consistently object oriented.<ref>{{cite web |url= http://www.python.org/doc/2.2.3/whatsnew/sect-rellinks.html|title= PEPs 252 and 253: Type and Class Changes|accessdate=2008-09-05 |author= A.M. Kuchling|date= 2001-12-21|work= What's New in Python 2.2|publisher= Python Foundation}}</ref> Also added were [[generator (computer science)|generator]]s which were inspired by [[Icon (programming language)|Icon]].<ref>{{cite web |url= http://www.python.org/doc/2.2.3/whatsnew/node5.html|title= PEP 255: Simple Generators|accessdate=2008-09-05 |author= A.M. Kuchling|date= 2001-12-21|work= What's New in Python 2.2|publisher= Python Foundation}}</ref>

===Java legacy===
Python's standard library additions and syntactical choices were strongly influenced by [[Java (programming language)|Java]] in some cases: the <code>logging</code> package,<ref>[http://www.python.org/dev/peps/pep-0282/ PEP 282 - A Logging System<!-- Bot generated title -->]</ref> introduced in version 2.3,<ref>[http://www.python.org/doc/2.3/whatsnew/node9.html 8 PEP 282: The logging Package<!-- Bot generated title -->]</ref> the [[SAX]] parser, introduced in 2.0, and the [[Python syntax and semantics#Decorators|decorator]] syntax that uses <code>@</code>,<ref>[http://www.python.org/dev/peps/pep-0318/ PEP 318 - Decorators for Functions and Methods<!-- Bot generated title -->]</ref> added in version 2.4<ref>[http://www.python.org/doc/2.4/whatsnew/node6.html 5 PEP 318: Decorators for Functions and Methods<!-- Bot generated title -->]</ref>

==Future development==
A Python Enhancement Proposal (or "PEP") is a standardized design document providing general information related to Python, including proposals, descriptions, and explanations for language features. PEPs are intended as the primary channel for proposing new features, and for documenting the underlying design rationale for all major elements of Python.<ref name="PepCite000">[http://www.python.org/dev/peps/pep-0001/ PEP 1 -- PEP Purpose and Guidelines]</ref> Outstanding PEPs are reviewed and commented upon by van Rossum, the BDFL.<ref name="PepCite001">[http://www.python.org/doc/essays/pepparade.html Parade of the PEPs<!-- Bot generated title -->]</ref>

===Python 3000===
There are plans for a future version, to be 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".

====Philosophy====
Python 3.0 is being developed with the same philosophy as in prior versions, so any reference to [[#Programming philosophy|Python philosophy]] will apply to Python 3.0 as well. However, as Python has accumulated new and redundant ways to program the same task, Python 3.0 has an emphasis on removing duplicative constructs and modules, in keeping with “There should be one—and preferably only one—obvious way to do it”.

Nonetheless, Python 3.0 will remain a [[Multi-paradigm programming language|multi-paradigm language]]. Coders will still have options among [[object orientation]], [[structured programming]], [[functional programming]], and [[aspect-oriented programming]] and other paradigms, but within such broad choices, the details are intended to be more obvious in Python 3.0 than they have become in Python 2.x.

====Timeline and compatibility====
The first release candidate of Python 3.0 was released on September 17, 2008.<ref>[http://python.org/download/releases/3.0/ Python 3.0rc1 Release]</ref>
The Python 2.x and Python 3.x series will coexist for several releases in parallel, where the 2.x series exists largely for compatibility and with some new features being backported from the 3.x series. [http://www.python.org/dev/peps/pep-3000/ PEP 3000] contains more information about the release schedule.

Python 3.0 will break [[backward compatibility]]. There is no requirement that Python 2.x code will run unmodified on Python 3.0. There are basic changes such as changing the print statement into a print function (so any use of print as a statement will cause the program to fail), and switching to Unicode for all text strings. Python's [[dynamic typing]] combined with the plans to change the semantics of certain methods of dictionaries, for example, makes perfect [[source-to-source compiler|mechanical translation]] from Python 2.x to Python 3.0 very difficult. However, a tool called "2to3" does most of the job of translation, pointing out areas of uncertainty using comments or warnings. Even in an alpha stage, 2to3 appears to be fairly successful at performing the translation.<ref>Sam Ruby, [http://intertwingly.net/blog/2007/09/01/2to3 2to3], September 1, 2007</ref> [http://www.python.org/dev/peps/pep-3000/ PEP 3000] recommends keeping one source (for the 2.x series), and producing releases for the Python 3.x platform using 2to3. The resulting code should not be edited until the program no longer needs to run on Python 2.x.

Python 2.6 includes forward compatibility features, as well as a "warnings" mode that will warn of potential transition problems. Warnings will be reported for builtins which will no longer exist in 3.0, as well as various old Python 2.x features that Python 3.0 will remove (see [http://www.python.org/dev/peps/pep-0361/ PEP 361] for more information).

====Features====
Some of the major changes scheduled for Python 3.0 are:

* Changing <code>print</code> so that it is a built-in function, not a statement. This makes it easier to change a module to use a different print function, as well as making the syntax more regular. In Python 2.6 this can be enabled by entering <code>from __future__ import print_function</code>.<ref>[http://www.python.org/dev/peps/pep-3105/ PEP 3105]</ref>
* Moving <code>reduce</code> (but not <code>map</code> or <code>filter</code>) out of the built-in namespace and into functools (the rationale being that operations using ''reduce'' are expressed more clearly using an accumulation loop);<ref>[http://www.artima.com/weblogs/viewpost.jsp?thread=211200 Thread on Artima programmer blog]</ref>
* Adding support for optional function annotations that can be used for informal type declarations or other purposes;<ref>[http://www.python.org/dev/peps/pep-3107/ PEP 3197]</ref>
* Unifying the <code>str</code>/<code>unicode</code> types, representing text, and introducing a separate immutable <code>bytes</code> type; and a mostly corresponding mutable <code>bytearray</code> type, which both represent arrays of [[byte]]s;<ref>[http://www.python.org/dev/peps/pep-3137/ PEP 3137]: Immutable Bytes and Mutable Buffer</ref>
* Removing backward-compatibility features, including old-style classes, integer-truncating division, string exceptions, and implicit relative imports.

==Usage==
{{main|Python software}}
Some of the largest projects that use Python are the [[Zope]] application server, [[YouTube]]<ref>[http://www.python.org/about/quotes/ Quotes about Python<!-- Bot generated title -->]</ref><ref>[http://sayspy.blogspot.com/2006/12/youtube-runs-on-python.html Coder Who Says Py: YouTube runs on Python!<!-- Bot generated title -->]</ref><ref>[http://mail.python.org/pipermail/python-dev/2006-December/070323.html [Python-Dev&#93; [Python-checkins&#93; MSI being downloaded 10x morethan all other files?!<!-- Bot generated title -->]</ref>, and the original [[BitTorrent (software)|BitTorrent client]]. Large organizations that make use of Python include [[Google]]<ref>[http://python.org/about/quotes/ Quotes about Python<!-- Bot generated title -->]</ref>, [[Yahoo!]], [[CERN]] and [[NASA]].<ref>[http://www.python.org/about/success/usa/ Python Success Stories<!-- Bot generated title -->]</ref> [[ITA Software|ITA]] uses Python for some of its components.<ref>[http://www.eweek.com/c/a/Application-Development/Python-Slithers-into-Systems/ Python Slithers into Systems by Darryl K. Taft]</ref>

===Information Security===
Python has also seen extensive use in the [[information security]] industry. Notably, in several of the tools offered by Immunity Security,<ref>[http://www.immunitysec.com/products-immdbg.shtml IMMUNITY : Knowing You're Secure<!-- Bot generated title -->]</ref><ref>[http://www.immunitysec.com/resources-freesoftware.shtml IMMUNITY : Knowing You're Secure<!-- Bot generated title -->]</ref> in several of the tools offered by Core Security,<ref>[http://oss.coresecurity.com/ CORE Security Technologies' open source software repository]</ref> in the Web [[application security]] scanner Wapiti,<ref>[http://wapiti.sourceforge.net/ Wapiti - Web application security auditor<!-- Bot generated title -->]</ref> and in the [[fuzzer]] TAOF.<ref>[http://www.theartoffuzzing.com/joomla/ TAOF - theartoffuzzing.com - Home<!-- Bot generated title -->]</ref> Python is commonly used in exploit development.<ref>[http://www1.corest.com/files/files/13/CanSecWest2002.pdf Core Security | Home<!-- Bot generated title -->]</ref><ref>[http://fist.immunitysec.com/pipermail/dailydave/2004-September/000851.html [Dailydave&#93; RE: Network Exploitation Tools aka Exploitation Engines<!-- Bot generated title -->]</ref>

===Embedding===
Python has been successfully embedded in a number of software products as a scripting language. It is commonly used in 3D animation packages, as in [[Houdini (software)|Houdini]], [[Maya (software)|Maya]], [[Softimage XSI]], [[TrueSpace]], [[Poser]], [[Modo (software)|Modo]], [[Nuke (software)|Nuke]] and [[Blender (software)|Blender]]. It is also used in [[GIMP]], [[Krita]], [[Inkscape]], [[Scribus]] and [[Paint Shop Pro]].<ref>Documentation of the PSP Scripting API can be found at [http://www.jasc.com/support/customercare/articles/psp9components.asp ''JASC Paint Shop Pro 9: Additional Download Resources'']</ref> [[ESRI]] is now promoting Python as the best choice for writing scripts in [[ArcGIS]].<ref>{{cite web|title=About getting started with writing geoprocessing scripts | url=http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=About_getting_started_with_writing_geoprocessing_scripts | year=2006 | month=Nov | accessyear=2007 | accessmonth=Apr}}</ref> It is also used in games like [[Civilization IV]] and [[Mount&Blade]] as the control language for modding and event interaction.<ref>[http://www.2kgames.com/civ4/blog_03.htm Civilization IV<!-- Bot generated title -->]</ref> [[Eve Online]], an [[MMORPG]], is also built using Python.<ref>[http://myeve.eve-online.com/devblog.asp?a=blog&bid=488. EVE Online | EVE Insider | Dev Blog<!-- Bot generated title -->]</ref>

===Availability===
For many operating systems, Python is a standard component; it ships with most [[Linux distribution]]s, with [[NetBSD]], and [[OpenBSD]], and with [[Mac OS X]]. [[Red Hat Linux]] and [[Fedora (operating system)|Fedora]] both use the pythonic [[Anaconda (installer)|Anaconda]] installer. [[Gentoo Linux]] uses Python in its [[package management]] system, [[Portage (software)|Portage]], and the standard tool to access it, [[Portage (software)#emerge|emerge]]. [[Pardus (operating system)|Pardus]] uses it for administration and during system boot.<ref>[http://www.pardus.org.tr/eng/projects/comar/PythonInPardus.html :: Pardus :: TÜBİTAK/UEKAE ::<!-- Bot generated title -->]</ref>

==Syntax and semantics==
[[Image:Python add5 syntax.svg|thumb|360px|[[Syntax highlighting|Syntax-highlighted]] Python code.]]
{{main|Python syntax and semantics}}

Python was intended to be a highly readable language. It aims toward an uncluttered visual layout, frequently using English keywords where other languages use punctuation. Python requires less [[boilerplate (text)|boilerplate]] than traditional statically-typed structured languages such as C or [[Pascal programming language|Pascal]], and has a smaller number of syntactic exceptions and special cases than either of these.<ref>{{ cite web | title = Is Python a good language for beginning programmers? | url = http://www.python.org/doc/faq/general/#is-python-a-good-language-for-beginning-programmers | work = General Python FAQ | date = March 7, 2005 | accessdate = 2007-03-21 | publisher = Python Foundation }}</ref>

===Indentation===
Python uses [[whitespace (computer science)|whitespace]] indentation, rather than [[curly bracket programming language|curly braces]] or keywords, to delimit [[statement block]]s (a feature also known as the [[off-side rule]]). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.

===Statements and control flow===
Python's statements include:
* The [[if-then-else|<code>if</code> statement]], which conditionally executes a block of code, along with <code>else</code> and <code>elif</code> (a contraction of else-if).
* The [[for loop|<code>for</code> statement]], which iterates over an iterable object, capturing each element to a local variable for use by the attached block.
* The <code>class</code> statement, which executes a block of code and attaches its local namespace to a [[class (computer science)|class]], for use in [[object oriented programming]].
* The <code>def</code> statement, which defines a [[function (computing)|function]].
* The <code>with</code> statement which encloses a code block within a context manager (for example, acquiring a [[lock (computer science)|lock]] before the block of code is run, and releasing the lock afterwards).

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

CPython does not support [[continuation]]s, and according to Guido van Rossum it never will.<ref>{{ cite web | title = Language Design Is Not Just Solving Puzzles | url = http://www.artima.com/weblogs/viewpost.jsp?thread=147358 | first = Guido | last = van Rossum | date = February 9, 2006 | accessdate = 2007-03-21 | work = Artima forums | publisher = Artima }}</ref> However, better support for [[coroutine]]-like functionality is provided in 2.5, by extending Python's [[generator (computer science)|generators]].<ref>{{ cite web | url = http://www.python.org/peps/pep-0342.html | title = Coroutines via Enhanced Generators | date = April 21, 2006 | first = Guido | last = van Rossum | coauthors = Phillip J. Eby | work = Python Enhancement Proposals | publisher = Python Foundation | accessdate = 2007-03-21 }}</ref> Prior to 2.5, generators were [[lazy evaluation|lazy]] [[iterator]]s &mdash; information was passed unidirectionally out of the generator. As of Python 2.5, it is possible to pass information back into a generator function.

===Methods===
[[Method (programming)|Method]]s on objects are [[function (programming)|function]]s attached to the object's class; the syntax <code>instance.method(argument)</code> is, for normal methods and functions, [[syntactic sugar]] for <code>Class.method(instance, argument)</code>. Python methods have an explicit <code>[[This (computer science)|self]]</code> parameter to access [[instance data]], in contrast to the implicit self in some other object-oriented programming languages (for example, [[Java (programming language)|Java]], [[C++]] or [[Ruby (programming language)|Ruby]]).<ref>{{ cite web | url = http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls | title = Why must 'self' be used explicitly in method definitions and calls? | work = Python FAQ | publisher = Python Foundation }}</ref>

===Typing===
Python uses [[duck typing]] and has typed objects but untyped variable names. 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 nonsense operations (for example, adding a number to a string) rather than silently attempting to make sense of them.

{| class="wikitable"
! Type
! Description
! Syntax Example
|-
| <code>[[string (computer science)|str]]</code>, <code>[[unicode]]</code>
| An [[Immutable object|immutable]] sequence of characters
| <code>'Wikipedia'</code>, <code>u'Wikipedia'</code>
|-
| <code>[[list (computer science)|list]]</code>
| [[Immutable object|Mutable]], can contain mixed types
| <code>[4.0, 'string', True]</code>
|-
| <code>[[tuple]]</code>
| [[Immutable object|Immutable]], can contain mixed types
| <code>(4.0, 'string', True)</code>
|-
| <code>[[set (computer science)|set]]</code>, <code>frozenset</code>
| Unordered, contains no duplicates
| <code>set([4.0, 'string', True])</code><br /><code>frozenset([4.0, 'string', True])</code>
|-
| <code>[[associative array|dict]]</code>
| Group of key and value pairs
| <code>{'key1': 1.0, 'key2': False}</code>
|-
| <code>[[integer (computer science)|int]]</code>
| A [[fixed precision]] number<br />(will be transparently expanded to an unlimited precision <code>long</code>, when it overflows the storage for an integer.)
| <code>42</code><br /><code>2147483648L</code>
|-
| <code>[[floating point|float]]</code>
| A [[real number]]
| <code>3.1415927</code>
|-
| <code>[[complex number|complex]]</code>
| A [[complex number]] with real number and imaginary parts
| <code>3+2j</code>
|-
|<code>[[truth value|bool]]</code>
| truth value
|<code>True</code> or <code>False</code>
|}

Python also allows programmers to define their own types. This is done using [[class (computer science)|class]]es, which are most often used for an [[object-oriented]] style of programming. New [[instance (programming)|instance]]s of classes are constructed by calling the class (eg, <code>FooClass()</code>), and the classes themselves are instances of the class <code>type</code> (itself an instance of itself), allowing [[metaprogramming]] and [[reflection (programming)|reflection]].

==Implementations==
The mainstream Python implementation, also known as ''[[CPython]]'', is written in [[C (programming language)|C]] meeting the [[C89 (C version)|C89]] standard,<ref>[http://www.python.org/dev/peps/pep-0007/ PEP 7 - Style Guide for C Code<!-- Bot generated title -->]</ref>. CPython compiles the Python program into intermediate byte code<ref>[http://docs.python.org/lib/bytecodes.html CPython byte code]</ref>, which is then executed by the virtual machine<ref>[http://www.troeger.eu/teaching/pythonvm08.pdf Python 2.5 internals]</ref>. It is distributed with a large standard library written in a mixture of C and Python. CPython ships in versions for many platforms, including [[Microsoft Windows]] and most modern [[Unix-like]] systems. CPython was intended from almost its very conception to be cross-platform; its use and development on esoteric platforms such as Amoeba, alongside more conventional ones like [[Unix]], or [[Macintosh]] has greatly helped in this regard.<ref>[http://www.oreilly.com/pub/a/oreilly/frank/rossum_1099.html O'Reilly - An Interview with Guido van Rossum<!-- Bot generated title -->]</ref>

[[Stackless Python]] is a significant fork of CPython that implements [[microthread]]s; it does not use the C memory stack. CPython uses a GIL to allow only one thread to execute at a time while the Stackless Python threads are independent of the OS and can run concurrently. Stackless Python is better suited to scalable tasks and for use on microcontrollers or other limited resource platforms due to the thread's light weight. It can be expected to run on approximately the same platforms that CPython runs on.

[[Jython]] compiles the Python program into Java byte code, which can then be executed by every [[Java Virtual Machine]] implementation. This also enables the utilization of Java class library functions from the Python program. [[IronPython]] follows a similar approach in order to run Python programs on the .NET [[Common Language Runtime]].

[[PyPy]] is an experimental [[self-hosting]] implementation of Python, written in Python, that can output several types of [[bytecode]], [[object code]] and [[intermediate language]]s.

Several programs exist to package the Python interpreter with application programs (or scripts) as standalone UNIX, Linux, Windows or Mac OS X executables, including [http://wiki.python.org/moin/Freeze Freeze], a pure Python utility that ships with Python, or [http://www.py2exe.org/ py2exe], [http://pyinstaller.python-hosting.com/ PyInstaller], [http://python.net/crew/atuining/cx_Freeze/ cx_Freeze] and [http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html py2app], all of which are available separately. Many third-party libraries for Python (and even some first-party ones) are only available on Windows, Linux, BSD, and Mac OS X.

In 2005 [[Nokia]] released a Python interpreter for the [[Series 60]] [[mobile phone]]s called [[PyS60]]. It includes many of the modules from the CPython implementations, but also some additional modules for integration with the [[Symbian]] operating system. This project has been kept up to date to run on all variants of the S60 platform and there are several third party modules available such as [http://pdis.hiit.fi/pdis/download/miso/ Miso] and [http://cyke64.googlepages.com/ uitricks].

''[http://www.chinesepython.org/cgi_bin/cgb.cgi/english/english.html ChinesePython]'' (中蟒) is a Python programming language using Chinese language lexicon. Besides reserved words and variable names, most data type operations can be coded in Chinese as well.

===Interpretational semantics===
<!-- Deleted image removed: [[Image:IDLE Windows.png|thumb|379px|CPython's interactive mode, used via IDLE]] -->

Most Python implementations (including CPython, the primary implementation) can function as a [[command line interpreter]], for which the user enters statements sequentially and receives the results immediately. In short, Python acts as a [[shell (computing)|shell]]. While the semantics of the other modes of execution (bytecode compilation, or compilation to native code) preserve the sequential semantics, they offer a speed boost at the cost of interactivity, so they are usually only used outside of a command-line interaction (eg, when importing a module).

Other shells add capabilities beyond those in the basic interpreter, including [[IDLE (Python)|IDLE]] and [[IPython]]. While generally following the visual style of the Python shell, they implement features like auto-completion, retention of session state, and syntax highlighting.

Some implementations can compile not only to bytecode, but can turn Python code into [[machine code]]. So far, this has only been done for restricted subsets of Python. PyPy takes this approach, naming its restricted compilable version of Python ''[[RPython]]''.

[[Psyco]] is a [[specialising compiler|specialising]] [[just in time compiler]] which transforms bytecode to machine code at runtime. The produced code is specialised for certain [[data types]] and is faster than standard Python code. Psyco is compatible with all Python code, not only a subset.<ref>[http://psyco.sourceforge.net/introduction.html Introduction to Psyco]</ref>

==Standard library==
Python has a large standard library, commonly cited as one of Python's greatest strengths,<ref>http://www.oracle.com/technology/pub/articles/piotrowski-pythoncore.html</ref> providing pre-written tools suited to many tasks. This is deliberate and has been described as a "batteries included" Python philosophy. The modules of the standard library can be augmented with custom modules written in either C or Python. Recently, [[Boost C++ Libraries]] includes a library, Boost.Python, to enable interoperability between C++ and Python. Because of the wide variety of tools provided by the standard library, combined with the ability to use a lower-level language such as C and C++, which is already capable of interfacing between other libraries, Python can be a powerful [[glue language]] between languages and tools.

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 [[Hypertext Transfer Protocol|HTTP]]) already supported. Modules for creating [[graphical user interface]]s, connecting to [[relational database]]s, arithmetic with arbitrary precision decimals, and manipulating [[regular expression]]s are also included.<ref>[http://www.python.org/peps/pep-0327.html PEP 327 - Decimal Data Type<!-- Bot generated title -->]</ref> Python also includes a [[unit testing]] framework for creating test suites.

Some parts of the standard library are covered by specifications (for example, the [[Web Server Gateway Interface|WSGI]] implementation <code>wsgiref</code> follows [http://www.python.org/dev/peps/pep-0333/ PEP 333]), but the majority of the modules are not. They are specified by their code, internal documentation, and test suite (if supplied). However, because most of the standard library is cross-platform Python code, there are only a few modules that must be altered or completely rewritten by alternative implementations.

==Programming philosophy==
Python is a [[multi-paradigm programming language]]. This means that, rather than forcing programmers to adopt a particular style of programming, it permits several styles: [[object oriented]] and [[structured programming]] are fully supported, and there are a number of language features which support [[functional programming]] and [[aspect-oriented programming]]. Many other paradigms are supported using extensions, such as [http://www.nongnu.org/pydbc/ pyDBC] and [http://www.wayforward.net/pycontract/ Contracts for Python] which allow [[Design by Contract]]. Python uses [[dynamic typing]] and a combination of [[reference counting]] and a cycle detecting [[Garbage collection (computer science)|garbage collector]] for [[memory management]]. An important feature of Python is dynamic [[name resolution]], which binds method and variable names during program execution (also known as [[late binding]]).

Another target of the language's design is ease of extensibility, rather than having everything built into the language core. New built-in modules are easily written in [[C (programming language)|C]] or [[C++]]. Python can also be used as an extension language for existing modules and applications that need a programmable interface. This design, of a small core language with a large standard library and an easily-extensible interpreter, was intended by van Rossum from the very start, due to his frustrations with [[ABC (programming language)|ABC]], which espoused the opposite mindset.<ref name="venners-interview-pt-1" />

The design of Python offers limited support for [[functional programming]] in the [[Lisp programming language|Lisp]] tradition. However, there are significant parallels between the philosophy of Python and that of minimalist Lisp-family languages such as [[Scheme (programming language)|Scheme]]. The library has two modules (itertools and functools) that implement proven functional tools borrowed from [[Haskell (programming language)|Haskell]] and [[Standard ML]].<ref>[http://docs.python.org/lib/module-itertools.html 6.5 itertools - Functions creating iterators for efficient looping<!-- Bot generated title -->]</ref>

While offering choice in coding methodology, the Python philosophy rejects 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". As [[Alex Martelli]] put it in his ''Python Cookbook'' (2nd ed., p.230): "To describe something as clever is NOT considered a compliment in the Python culture." Python's philosophy rejects the Perl "[[there is more than one way to do it]]" approach to language design in favor of "there should be one—and preferably only one—obvious way to do it".<ref>[http://www.python.org/dev/peps/pep-0020/ PEP 20 - The Zen of Python<!-- Bot generated title -->]</ref>

Python eschews [[Optimization (computer science)#When to optimize|premature optimization]], and moreover, rejects patches to non-critical parts of CPython which would offer a marginal increase in speed at the cost of clarity.<ref>[http://www.python.org/dev/culture/ Python Culture]</ref> It is sometimes described as 'slow'.<ref>[http://peter.mapledesign.co.uk/weblog/archives/python-is-slow Python is... slow? — Peter Bowyer’s weblog]</ref> However, most problems are not speed critical, and as computer hardware continues to become exponentially faster, languages do have more hardware resources available. When speed is a problem, Python programmers tend to try to optimize [[bottleneck (engineering)|bottleneck]]s by algorithm improvements or data structure changes, using a JIT compiler such as Psyco, rewriting the time-critical functions in "closer to the metal" languages such as C, or by translating Python code to C code using tools like [http://cython.org Cython].<ref>[http://www.python.org/doc/essays/list2str.html Python Patterns - An Optimization Anecdote]</ref>

===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 pythonicity is tightly bound to Python's minimalist philosophy of readability and avoiding the "there's more than one way to do it" approach. 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''.

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 [[Language binding|binding]] of [[Simple DirectMedia Layer|SDL]] to Python (commonly used to create games); [[PyS60]], an implementation for the Symbian Series 60 Operating System; [[PyQt]] and [[PyGTK]], which bind [[Qt (toolkit)|Qt]] and [[GTK]], respectively, to Python; and [[PyPy]], a Python implementation written in Python. The prefix is also used outside of naming software packages: the major Python [[Academic conference|conference]] is named [[PyCon]].

An important goal of the Python developers is making Python fun to use. This is reflected in the origin of the name (based on 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.<ref>[http://docs.python.org/tut/node3.html Python Tutorial]</ref> For example, the [[metasyntactic variable]]s often used in Python literature are [[Spam (Monty Python)|''spam'' and ''eggs'']], instead of the traditional [[foobar|''foo'' and ''bar'']].

==Influences on other languages==
Python's design and philosophy have influenced several programming languages:

* [[Boo (programming language)|Boo]] uses indentation, a similar syntax, and a similar object model. However, Boo uses [[static typing]] and is closely integrated with the [[.NET framework]].<ref>[http://boo.codehaus.org/Gotchas+for+Python+Users BOO - Gotchas for Python Users<!-- Bot generated title -->]</ref>
* [[Cobra (programming language from Cobra Language LLC)|Cobra]] is also similar to Python, using indentation for blocks. It offers optional static typing and generates code designed for .NET/Mono. Cobra directly supports [[Design by contract|design-by-contract]] contracts.<ref>[http://cobra-language.com/docs/python/ Comparison to Python], cobra-language.com</ref>
* [[ECMAScript]] borrowed [[Iterator#Python|iterators]], [[Generator (computer science)|generators]] and [[list comprehension]]s from Python.<ref>[http://wiki.ecmascript.org/doku.php?id=proposals:iterators_and_generators proposals:iterators_and_generators [ES4 Wiki&#93;<!-- Bot generated title -->]</ref>
* [[Groovy (programming language)|Groovy]] was motivated by the desire to bring the Python design philosophy to [[Java (programming language)|Java]].<ref>{{cite web
| author = James Strachan
| date = 2003-08-29
| title = Groovy - the birth of a new dynamic language for the Java platform
| url = http://radio.weblogs.com/0112098/2003/08/29.html
}}</ref>
* [[Converge (programming language)|Converge]] is syntactically similar to Python, but has an interesting approach to [[Generator (computer science)|generators]] and [[backtracking]] as well as [[Macro (computer science)|macros]] and compile-time [[metaprogramming]].<ref>{{cite web
| author = Laurence Tratt
| title = Converge - About
| url = http://convergepl.org/about.html
}}</ref>
* [[OCaml]] has an optional syntax, called twt (That Whitespace Thing), inspired by Python, and a new Batteries Included approach, also inspired by Python.<ref>{{cite web
| author = David Teller
| title = OCaml Batteries Included
| url = http://forge.ocamlcore.org/projects/batteries/}}</ref>

Python's development practices have also been emulated by other languages. The practice of requiring a document describing the rationale for, and issues surrounding, a change to the language (ie, a PEP) is also used in [[Tcl]] because of Python's influence.<ref>[http://www.tcl.tk/cgi-bin/tct/tip/3.html TIP #3: TIP Format<!-- Bot generated title -->]</ref>

== References ==

{{refs|2}}

== See also ==
* [[List of programming languages]]
* [[Comparison of computer shells]]
* [[Comparison of programming languages]]
* [[List of applications written in Python]]
* [[List of integrated development environments for Python]]
* [[Guido van Robot]]
* [[Scripting language]]

==External links==
{{wikibooks|Python Programming}}
{{Commonscat}}
{{wikiversity|Python Programming}}
{{wikiquote|Python}}
* [http://www.python.org/ Python Official Website]
* [http://www.python.org/doc/ Official documentation and resources]
* [http://www.computerworld.com.au/index.php/id;66665771 Computerworld Interview with Guido Van Rossum on Python]
* {{dmoz|Computers/Programming/Languages/Python|Python}}

<!--===========================({{NoMoreLinks}})===============================
| PLEASE BE CAUTIOUS IN ADDING MORE LINKS TO THIS ARTICLE. WIKIPEDIA IS |
| NOT A COLLECTION OF LINKS. |
| |
| Excessive or inappropriate links WILL BE DELETED. |
| See [[Wikipedia:External links]] and [[Wikipedia:Spam]] for details. |
| |
| If there are already plentiful links, please propose additions or |
| replacements on this article's discussion page. Or submit your link |
| to the appropriate category at the Open Directory Project (www.dmoz.org)|
| and link back to that category using the {{dmoz}} template. |
===========================({{NoMoreLinks}})===============================-->
{{FOSS}}

[[Category:Python programming language| ]]
[[Category:Class-based programming languages]]
[[Category:Object-oriented programming languages]]
[[Category:Dynamically-typed programming languages]]
[[Category:Scripting languages]]
[[Category:Unix software]]
[[Category:Cross-platform software]]

{{Link FA|ru}}
[[ar:بايثون]]
[[an:Python]]
[[az:Python]]
[[bs:Python programski jezik]]
[[bg:Python]]
[[ca:Python]]
[[cs:Python]]
[[da:Python (programmeringssprog)]]
[[de:Python (Programmiersprache)]]
[[el:Python]]
[[es:Python]]
[[et:Python (programmeerimiskeel)]]
[[eo:Python (programlingvo)]]
[[eu:Python]]
[[fa:زبان برنامه‌نویسی پایتون]]
[[fr:Python (langage)]]
[[gl:Python]]
[[ko:파이썬]]
[[is:Python (forritunarmál)]]
[[it:Python]]
[[he:Python]]
[[ka:პითონი (პროგრამირების ენა)]]
[[la:Python]]
[[lt:Python]]
[[hu:Python (programozási nyelv)]]
[[ml:പൈത്തണ്‍]]
[[ms:Python]]
[[nl:Python (programmeertaal)]]
[[ja:Python]]
[[no:Python]]
[[pl:Python]]
[[pt:Python]]
[[ro:Python]]
[[ru:Python]]
[[sq:Python]]
[[simple:Python (programming language)]]
[[sk:Python (programovací jazyk)]]
[[sl:Python (programski jezik)]]
[[sr:Програмски језик Пајтон]]
[[fi:Python]]
[[sv:Python (programspråk)]]
[[ta:பைத்தோன்]]
[[te:పైథాన్ (కంప్యూటర్ భాష)]]
[[th:ภาษาไพทอน]]
[[vi:Python (ngôn ngữ lập trình)]]
[[tr:Python (programlama dili)]]
[[bug:Python]]
[[uk:Python]]
[[zh:Python]]

Revision as of 17:58, 12 October 2008

Python
File:Python logo.svg
Paradigmmulti-paradigm: object-oriented, imperative, functional
Designed byGuido van Rossum
DeveloperPython Software Foundation
First appeared1991
Stable release
2.6 / October 1, 2008 (2008-10-01)
Preview release
3.0rc1 / September 17, 2008 (2008-09-17)
Typing disciplinestrong, dynamic, duck
OSCross-platform
LicensePython Software Foundation License
Websitehttp://www.python.org/
Major implementations
CPython, Jython, IronPython, PyPy
Dialects
Stackless Python, RPython
Influenced by
ABC, ALGOL 68,[1] C, Haskell, Icon, Lisp, Modula-3, Perl, Java
Influenced
Boo, Groovy, Ruby, Cobra, D

Python is a general-purpose, high-level programming language.[2] Its design philosophy emphasizes programmer productivity and code readability.[3] Python's core syntax and semantics are minimalistic, while the standard library is large and comprehensive. Its use of whitespace as block delimiters is unusual among popular programming languages.

Python supports multiple programming paradigms (primarily object oriented, imperative, and functional) and features a fully dynamic type system and automatic memory management, similar to Perl, Ruby, Scheme, and Tcl. Like other dynamic languages, Python is often used as a scripting language.

Python was first released by Guido van Rossum in 1991.[4] The language has an open, community-based development model managed by the non-profit Python Software Foundation, which also maintains the de facto standard definition of the language in CPython, the reference implementation.

History

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

Python was conceived in the late 1980s[5] by Guido van Rossum at CWI in the Netherlands as a successor to the ABC programming language capable of exception handling and interfacing with the Amoeba operating system.[6] Van Rossum is Python's principal author, and his continuing central role in deciding the direction of Python is reflected in the title given him by the Python community, Benevolent Dictator for Life (BDFL).

First publication

In 1991, van Rossum published the code (labeled version 0.9.0) to alt.sources.[4] Already present at this stage in development were classes with inheritance, exception handling, functions, and the core datatypes of list, dict, str and so on. Also in this initial release was a module system borrowed from Modula-3; van Rossum describes the module as "one of Python's major programming units".[5] Python's exception model also resembles Modula-3's, with the addition of an else clause.[6] In 1994 comp.lang.python, the primary discussion forum for Python, was formed, marking a milestone in the growth of Python's userbase.

Version 1.0

Python reached version 1.0 in January 1994. The major new features included in this release were the functional programming tools lambda, map, filter and reduce. Van Rossum stated that “Python acquired lambda, reduce(), filter() and map(), courtesy of (I believe) a Lisp hacker who missed them and submitted working patches.”[7]

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

By version 1.4, Python had acquired several new features. Notable among these are the Modula-3 inspired keyword arguments (which are also similar to Common Lisp's keyword arguments), and built-in support for complex numbers. Also included is a basic form of data hiding by name mangling, though this is easily bypassed.[8]

During van Rossum's stay at CNRI, he launched the Computer Programming for Everybody (CP4E) initiative, intending to make programming more accessible to more people, with a basic 'literacy' in programming languages, similar to the basic English literacy and mathematics skills required by most employers. Python served a central role in this: because of its focus on clean syntax, it was already suitable, and CP4E's goals bore similarities to its predecessor, ABC. The project was funded by DARPA.[9] As of 2007, the CP4E project is inactive, and while Python attempts to be easily learnable and not too arcane in its syntax and semantics, reaching out to non-programmers is not an active concern.[10]

BeOpen

In 2000, the Python core development team moved to BeOpen.com to form the BeOpen PythonLabs team. CNRI requested that a version 1.6 be released, summarizing Python's development up to the point at which the development team left CNRI. Consequently, the release schedules for 1.6 and 2.0 had a significant amount of overlap.[11] 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.

The Python 1.6 release included a new CNRI license that was substantially longer than the CWI license that had been used for earlier releases. The new license included a clause stating that the license was governed by the laws of the State of Virginia. The Free Software Foundation argued that the choice-of-law clause was incompatible with the GNU GPL. BeOpen, CNRI, and the FSF negotiated a change to Python's free software license that would make it GPL-compatible. 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.[12]

Version 2.0

Python 2.0 introduced list comprehensions, a feature borrowed from the functional programming languages SETL and Haskell. Python's syntax for this construct is very similar to Haskell's, apart from Haskell's preference for punctuation characters and Python's preference for alphabetic keywords. Python 2.0 also introduced a garbage collection system capable of collecting reference cycles.[11]

Python 2.1 was close to Python 1.6.1, as well as Python 2.0. Its license was renamed Python Software Foundation License. All code, documentation and specifications added, from the time of Python 2.1's alpha release on, is owned by the Python Software Foundation (PSF), a non-profit organization formed in 2001, modeled after the Apache Software Foundation.[12] The release included a change to the language specification to support nested scopes, like other statically scoped languages.[13] (The feature was turned off by default, and not required, until Python 2.2.)

A major innovation in Python 2.2 was the unification of Python's types (types written in C), and classes (types written in Python) into one hierarchy. This single unification made Python's object model purely and consistently object oriented.[14] Also added were generators which were inspired by Icon.[15]

Java legacy

Python's standard library additions and syntactical choices were strongly influenced by Java in some cases: the logging package,[16] introduced in version 2.3,[17] the SAX parser, introduced in 2.0, and the decorator syntax that uses @,[18] added in version 2.4[19]

Future development

A Python Enhancement Proposal (or "PEP") is a standardized design document providing general information related to Python, including proposals, descriptions, and explanations for language features. PEPs are intended as the primary channel for proposing new features, and for documenting the underlying design rationale for all major elements of Python.[20] Outstanding PEPs are reviewed and commented upon by van Rossum, the BDFL.[21]

Python 3000

There are plans for a future version, to be 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".

Philosophy

Python 3.0 is being developed with the same philosophy as in prior versions, so any reference to Python philosophy will apply to Python 3.0 as well. However, as Python has accumulated new and redundant ways to program the same task, Python 3.0 has an emphasis on removing duplicative constructs and modules, in keeping with “There should be one—and preferably only one—obvious way to do it”.

Nonetheless, Python 3.0 will remain a multi-paradigm language. Coders will still have options among object orientation, structured programming, functional programming, and aspect-oriented programming and other paradigms, but within such broad choices, the details are intended to be more obvious in Python 3.0 than they have become in Python 2.x.

Timeline and compatibility

The first release candidate of Python 3.0 was released on September 17, 2008.[22] The Python 2.x and Python 3.x series will coexist for several releases in parallel, where the 2.x series exists largely for compatibility and with some new features being backported from the 3.x series. PEP 3000 contains more information about the release schedule.

Python 3.0 will break backward compatibility. There is no requirement that Python 2.x code will run unmodified on Python 3.0. There are basic changes such as changing the print statement into a print function (so any use of print as a statement will cause the program to fail), and switching to Unicode for all text strings. Python's dynamic typing combined with the plans to change the semantics of certain methods of dictionaries, for example, makes perfect mechanical translation from Python 2.x to Python 3.0 very difficult. However, a tool called "2to3" does most of the job of translation, pointing out areas of uncertainty using comments or warnings. Even in an alpha stage, 2to3 appears to be fairly successful at performing the translation.[23] PEP 3000 recommends keeping one source (for the 2.x series), and producing releases for the Python 3.x platform using 2to3. The resulting code should not be edited until the program no longer needs to run on Python 2.x.

Python 2.6 includes forward compatibility features, as well as a "warnings" mode that will warn of potential transition problems. Warnings will be reported for builtins which will no longer exist in 3.0, as well as various old Python 2.x features that Python 3.0 will remove (see PEP 361 for more information).

Features

Some of the major changes scheduled for Python 3.0 are:

  • Changing print so that it is a built-in function, not a statement. This makes it easier to change a module to use a different print function, as well as making the syntax more regular. In Python 2.6 this can be enabled by entering from __future__ import print_function.[24]
  • Moving reduce (but not map or filter) out of the built-in namespace and into functools (the rationale being that operations using reduce are expressed more clearly using an accumulation loop);[25]
  • Adding support for optional function annotations that can be used for informal type declarations or other purposes;[26]
  • Unifying the str/unicode types, representing text, and introducing a separate immutable bytes type; and a mostly corresponding mutable bytearray type, which both represent arrays of bytes;[27]
  • Removing backward-compatibility features, including old-style classes, integer-truncating division, string exceptions, and implicit relative imports.

Usage

Some of the largest projects that use Python are the Zope application server, YouTube[28][29][30], and the original BitTorrent client. Large organizations that make use of Python include Google[31], Yahoo!, CERN and NASA.[32] ITA uses Python for some of its components.[33]

Information Security

Python has also seen extensive use in the information security industry. Notably, in several of the tools offered by Immunity Security,[34][35] in several of the tools offered by Core Security,[36] in the Web application security scanner Wapiti,[37] and in the fuzzer TAOF.[38] Python is commonly used in exploit development.[39][40]

Embedding

Python has been successfully embedded in a number of software products as a scripting language. It is commonly used in 3D animation packages, as in Houdini, Maya, Softimage XSI, TrueSpace, Poser, Modo, Nuke and Blender. It is also used in GIMP, Krita, Inkscape, Scribus and Paint Shop Pro.[41] ESRI is now promoting Python as the best choice for writing scripts in ArcGIS.[42] It is also used in games like Civilization IV and Mount&Blade as the control language for modding and event interaction.[43] Eve Online, an MMORPG, is also built using Python.[44]

Availability

For many operating systems, Python is a standard component; it ships with most Linux distributions, with NetBSD, and OpenBSD, and with Mac OS X. Red Hat Linux and Fedora both use the pythonic Anaconda installer. Gentoo Linux uses Python in its package management system, Portage, and the standard tool to access it, emerge. Pardus uses it for administration and during system boot.[45]

Syntax and semantics

Syntax-highlighted Python code.

Python was intended to be a highly readable language. It aims toward an uncluttered visual layout, frequently using English keywords where other languages use punctuation. Python requires less boilerplate than traditional statically-typed structured languages such as C or Pascal, and has a smaller number of syntactic exceptions and special cases than either of these.[46]

Indentation

Python uses whitespace indentation, rather than curly braces or keywords, to delimit statement blocks (a feature also known as the off-side rule). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.

Statements and control flow

Python's statements include:

  • The if statement, which conditionally executes a block of code, along with else and elif (a contraction of else-if).
  • The for statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block.
  • The class statement, which executes a block of code and attaches its local namespace to a class, for use in object oriented programming.
  • The def statement, which defines a function.
  • The with statement which encloses a code block within a context manager (for example, acquiring a lock before the block of code is run, and releasing the lock afterwards).

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

CPython does not support continuations, and according to Guido van Rossum it never will.[47] However, better support for coroutine-like functionality is provided in 2.5, by extending Python's generators.[48] Prior to 2.5, generators were lazy iterators — information was passed unidirectionally out of the generator. As of Python 2.5, it is possible to pass information back into a generator function.

Methods

Methods on objects are functions attached to the object's class; the syntax instance.method(argument) is, for normal methods and functions, syntactic sugar for Class.method(instance, argument). Python methods have an explicit self parameter to access instance data, in contrast to the implicit self in some other object-oriented programming languages (for example, Java, C++ or Ruby).[49]

Typing

Python uses duck typing and has typed objects but untyped variable names. 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 nonsense operations (for example, adding a number to a string) rather than silently attempting to make sense of them.

Type Description Syntax Example
str, unicode An immutable sequence of characters 'Wikipedia', u'Wikipedia'
list Mutable, can contain mixed types [4.0, 'string', True]
tuple Immutable, can contain mixed types (4.0, 'string', True)
set, frozenset Unordered, contains no duplicates set([4.0, 'string', True])
frozenset([4.0, 'string', True])
dict Group of key and value pairs {'key1': 1.0, 'key2': False}
int A fixed precision number
(will be transparently expanded to an unlimited precision long, when it overflows the storage for an integer.)
42
2147483648L
float A real number 3.1415927
complex A complex number with real number and imaginary parts 3+2j
bool truth value True or False

Python also allows programmers to define their own types. This is done using classes, which are most often used for an object-oriented style of programming. New instances of classes are constructed by calling the class (eg, FooClass()), and the classes themselves are instances of the class type (itself an instance of itself), allowing metaprogramming and reflection.

Implementations

The mainstream Python implementation, also known as CPython, is written in C meeting the C89 standard,[50]. CPython compiles the Python program into intermediate byte code[51], which is then executed by the virtual machine[52]. It is distributed with a large standard library written in a mixture of C and Python. CPython ships in versions for many platforms, including Microsoft Windows and most modern Unix-like systems. CPython was intended from almost its very conception to be cross-platform; its use and development on esoteric platforms such as Amoeba, alongside more conventional ones like Unix, or Macintosh has greatly helped in this regard.[53]

Stackless Python is a significant fork of CPython that implements microthreads; it does not use the C memory stack. CPython uses a GIL to allow only one thread to execute at a time while the Stackless Python threads are independent of the OS and can run concurrently. Stackless Python is better suited to scalable tasks and for use on microcontrollers or other limited resource platforms due to the thread's light weight. It can be expected to run on approximately the same platforms that CPython runs on.

Jython compiles the Python program into Java byte code, which can then be executed by every Java Virtual Machine implementation. This also enables the utilization of Java class library functions from the Python program. IronPython follows a similar approach in order to run Python programs on the .NET Common Language Runtime.

PyPy is an experimental self-hosting implementation of Python, written in Python, that can output several types of bytecode, object code and intermediate languages.

Several programs exist to package the Python interpreter with application programs (or scripts) as standalone UNIX, Linux, Windows or Mac OS X executables, including Freeze, a pure Python utility that ships with Python, or py2exe, PyInstaller, cx_Freeze and py2app, all of which are available separately. Many third-party libraries for Python (and even some first-party ones) are only available on Windows, Linux, BSD, and Mac OS X.

In 2005 Nokia released a Python interpreter for the Series 60 mobile phones called PyS60. It includes many of the modules from the CPython implementations, but also some additional modules for integration with the Symbian operating system. This project has been kept up to date to run on all variants of the S60 platform and there are several third party modules available such as Miso and uitricks.

ChinesePython (中蟒) is a Python programming language using Chinese language lexicon. Besides reserved words and variable names, most data type operations can be coded in Chinese as well.

Interpretational semantics

Most Python implementations (including CPython, the primary implementation) can function as a command line interpreter, for which the user enters statements sequentially and receives the results immediately. In short, Python acts as a shell. While the semantics of the other modes of execution (bytecode compilation, or compilation to native code) preserve the sequential semantics, they offer a speed boost at the cost of interactivity, so they are usually only used outside of a command-line interaction (eg, when importing a module).

Other shells add capabilities beyond those in the basic interpreter, including IDLE and IPython. While generally following the visual style of the Python shell, they implement features like auto-completion, retention of session state, and syntax highlighting.

Some implementations can compile not only to bytecode, but can turn Python code into machine code. So far, this has only been done for restricted subsets of Python. PyPy takes this approach, naming its restricted compilable version of Python RPython.

Psyco is a specialising just in time compiler which transforms bytecode to machine code at runtime. The produced code is specialised for certain data types and is faster than standard Python code. Psyco is compatible with all Python code, not only a subset.[54]

Standard library

Python has a large standard library, commonly cited as one of Python's greatest strengths,[55] providing pre-written tools suited to many tasks. This is deliberate and has been described as a "batteries included" Python philosophy. The modules of the standard library can be augmented with custom modules written in either C or Python. Recently, Boost C++ Libraries includes a library, Boost.Python, to enable interoperability between C++ and Python. Because of the wide variety of tools provided by the standard library, combined with the ability to use a lower-level language such as C and C++, which is already capable of interfacing between other libraries, Python can be a powerful glue language between languages and tools.

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) already supported. Modules for creating graphical user interfaces, connecting to relational databases, arithmetic with arbitrary precision decimals, and manipulating regular expressions are also included.[56] Python also includes a unit testing framework for creating test suites.

Some parts of the standard library are covered by specifications (for example, the WSGI implementation wsgiref follows PEP 333), but the majority of the modules are not. They are specified by their code, internal documentation, and test suite (if supplied). However, because most of the standard library is cross-platform Python code, there are only a few modules that must be altered or completely rewritten by alternative implementations.

Programming philosophy

Python is a multi-paradigm programming language. This means that, rather than forcing programmers to adopt a particular style of programming, it permits several styles: object oriented and structured programming are fully supported, and there are a number of language features which support functional programming and aspect-oriented programming. Many other paradigms are supported using extensions, such as pyDBC and Contracts for Python which allow Design by Contract. Python uses dynamic typing and a combination of reference counting and a cycle detecting garbage collector for memory management. An important feature of Python is dynamic name resolution, which binds method and variable names during program execution (also known as late binding).

Another target of the language's design is ease of extensibility, rather than having everything built into the language core. 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. This design, of a small core language with a large standard library and an easily-extensible interpreter, was intended by van Rossum from the very start, due to his frustrations with ABC, which espoused the opposite mindset.[5]

The design of Python offers limited support for functional programming in the Lisp tradition. However, there are significant parallels between the philosophy of Python and that of minimalist Lisp-family languages such as Scheme. The library has two modules (itertools and functools) that implement proven functional tools borrowed from Haskell and Standard ML.[57]

While offering choice in coding methodology, the Python philosophy rejects 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". As Alex Martelli put it in his Python Cookbook (2nd ed., p.230): "To describe something as clever is NOT considered a compliment in the Python culture." Python's philosophy rejects the Perl "there is more than one way to do it" approach to language design in favor of "there should be one—and preferably only one—obvious way to do it".[58]

Python eschews premature optimization, and moreover, rejects patches to non-critical parts of CPython which would offer a marginal increase in speed at the cost of clarity.[59] It is sometimes described as 'slow'.[60] However, most problems are not speed critical, and as computer hardware continues to become exponentially faster, languages do have more hardware resources available. When speed is a problem, Python programmers tend to try to optimize bottlenecks by algorithm improvements or data structure changes, using a JIT compiler such as Psyco, rewriting the time-critical functions in "closer to the metal" languages such as C, or by translating Python code to C code using tools like Cython.[61]

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 pythonicity is tightly bound to Python's minimalist philosophy of readability and avoiding the "there's more than one way to do it" approach. 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.

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); PyS60, an implementation for the Symbian Series 60 Operating System; PyQt and PyGTK, which bind Qt and GTK, respectively, to Python; and PyPy, a Python implementation written in Python. The prefix is also used outside of naming software packages: the major Python conference is named PyCon.

An important goal of the Python developers is making Python fun to use. This is reflected in the origin of the name (based on 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.[62] For example, the metasyntactic variables often used in Python literature are spam and eggs, instead of the traditional foo and bar.

Influences on other languages

Python's design and philosophy have influenced several programming languages:

Python's development practices have also been emulated by other languages. The practice of requiring a document describing the rationale for, and issues surrounding, a change to the language (ie, a PEP) is also used in Tcl because of Python's influence.[69]

References

  1. ^ "Interview with Guido van Rossum". 1998. {{cite web}}: Unknown parameter |accessmonthday= ignored (help); Unknown parameter |accessyear= ignored (|access-date= suggested) (help); Unknown parameter |month= ignored (help)
  2. ^ "What is Python Good For?". General Python FAQ. Python Foundation. Retrieved 2008-09-05.
  3. ^ "What is Python? Executive Summary". Python documentation. Python Foundation. Retrieved 2007-03-21.
  4. ^ a b "HISTORY". Python source distribution. Python Foundation. Retrieved 2007-03-21.
  5. ^ a b c "The Making of Python". Artima Developer. Retrieved 2007-03-22.
  6. ^ a b "Why was Python created in the first place?". Python FAQ. Retrieved 2007-03-22.
  7. ^ Guido van Rossum. "The fate of reduce() in Python 3000". Artima Developer. Retrieved 2007-03-22.
  8. ^ "LJ #37: Python 1.4 Update". Retrieved 2007-04-29.
  9. ^ Guido van Rossum. "Computer Programming for Everybody". Retrieved 2007-03-22.
  10. ^ "Computer Programming for Everybody". Python Software Foundation. Retrieved 2007-03-22.
  11. ^ a b A.M. Kuchling and Moshe Zadka. "What's New in Python 2.0". Retrieved 2007-03-22.
  12. ^ a b "History of the software". Python Library Reference. Retrieved 2007-03-22.
  13. ^ Jeremy Hylton. "Statically Nested Scopes". Retrieved 2007-03-22.
  14. ^ A.M. Kuchling (2001-12-21). "PEPs 252 and 253: Type and Class Changes". What's New in Python 2.2. Python Foundation. Retrieved 2008-09-05.
  15. ^ A.M. Kuchling (2001-12-21). "PEP 255: Simple Generators". What's New in Python 2.2. Python Foundation. Retrieved 2008-09-05.
  16. ^ PEP 282 - A Logging System
  17. ^ 8 PEP 282: The logging Package
  18. ^ PEP 318 - Decorators for Functions and Methods
  19. ^ 5 PEP 318: Decorators for Functions and Methods
  20. ^ PEP 1 -- PEP Purpose and Guidelines
  21. ^ Parade of the PEPs
  22. ^ Python 3.0rc1 Release
  23. ^ Sam Ruby, 2to3, September 1, 2007
  24. ^ PEP 3105
  25. ^ Thread on Artima programmer blog
  26. ^ PEP 3197
  27. ^ PEP 3137: Immutable Bytes and Mutable Buffer
  28. ^ Quotes about Python
  29. ^ Coder Who Says Py: YouTube runs on Python!
  30. ^ [Python-Dev] [Python-checkins] MSI being downloaded 10x morethan all other files?!
  31. ^ Quotes about Python
  32. ^ Python Success Stories
  33. ^ Python Slithers into Systems by Darryl K. Taft
  34. ^ IMMUNITY : Knowing You're Secure
  35. ^ IMMUNITY : Knowing You're Secure
  36. ^ CORE Security Technologies' open source software repository
  37. ^ Wapiti - Web application security auditor
  38. ^ TAOF - theartoffuzzing.com - Home
  39. ^ Core Security | Home
  40. ^ [Dailydave] RE: Network Exploitation Tools aka Exploitation Engines
  41. ^ Documentation of the PSP Scripting API can be found at JASC Paint Shop Pro 9: Additional Download Resources
  42. ^ "About getting started with writing geoprocessing scripts". 2006. {{cite web}}: Unknown parameter |accessmonth= ignored (|access-date= suggested) (help); Unknown parameter |accessyear= ignored (|access-date= suggested) (help); Unknown parameter |month= ignored (help)
  43. ^ Civilization IV
  44. ^ EVE Online | EVE Insider | Dev Blog
  45. ^ :: Pardus :: TÜBİTAK/UEKAE ::
  46. ^ "Is Python a good language for beginning programmers?". General Python FAQ. Python Foundation. March 7, 2005. Retrieved 2007-03-21.
  47. ^ van Rossum, Guido (February 9, 2006). "Language Design Is Not Just Solving Puzzles". Artima forums. Artima. Retrieved 2007-03-21.
  48. ^ van Rossum, Guido (April 21, 2006). "Coroutines via Enhanced Generators". Python Enhancement Proposals. Python Foundation. Retrieved 2007-03-21. {{cite web}}: Unknown parameter |coauthors= ignored (|author= suggested) (help)
  49. ^ "Why must 'self' be used explicitly in method definitions and calls?". Python FAQ. Python Foundation.
  50. ^ PEP 7 - Style Guide for C Code
  51. ^ CPython byte code
  52. ^ Python 2.5 internals
  53. ^ O'Reilly - An Interview with Guido van Rossum
  54. ^ Introduction to Psyco
  55. ^ http://www.oracle.com/technology/pub/articles/piotrowski-pythoncore.html
  56. ^ PEP 327 - Decimal Data Type
  57. ^ 6.5 itertools - Functions creating iterators for efficient looping
  58. ^ PEP 20 - The Zen of Python
  59. ^ Python Culture
  60. ^ Python is... slow? — Peter Bowyer’s weblog
  61. ^ Python Patterns - An Optimization Anecdote
  62. ^ Python Tutorial
  63. ^ BOO - Gotchas for Python Users
  64. ^ Comparison to Python, cobra-language.com
  65. ^ proposals:iterators_and_generators [ES4 Wiki]
  66. ^ James Strachan (2003-08-29). "Groovy - the birth of a new dynamic language for the Java platform".
  67. ^ Laurence Tratt. "Converge - About".
  68. ^ David Teller. "OCaml Batteries Included".
  69. ^ TIP #3: TIP Format

See also

External links

Template:Link FA