Notice: This page displays a fallback because interactive scripts did not run. Possible causes include disabled JavaScript or failure to load scripts or stylesheets.
...=[]): path = path + [start] if start == end: return path if not graph.has_key(start): return None shortest = None for node in graph[start]: if node not in path: newpath = find_shortest_path(graph, node, end, path) if newpath: if not shortest or len(newpath) < len(shortest): shortest = newpath return shortest Sample ru...
...= "" for i in range(0, 256, 16): # 0, 16, 32, 48, 64, ... s = "" for character in map(chr, list[i:i+16]): s = s + character string = string + s return string Unfortunately, for a list of 256 items, this version ran a bit slower (though within 20%) of f3(). Since writing a general version would only slow it down more, we didn't bother to pursue this path any further (except that we also compared it with a varian...
...= 1 b = 2 This can be though of as equivalent to: C = type(B)('C', (B,), {'a': 1, 'b': 2}) If that's too dense for you, here's the same thing written out using temporary variables: creator = type(B) # The type of the base class name = 'C' # The name of the new class bases = (B,) # A tuple containing the base class(es) namespace = {'a': 1, 'b': 2} # The namespace of the class statement C = creator(name, bases, ...
Glue It All Together With Python Glue It All Together With Python Guido van Rossum CNRI 1895 Preston White Drive Reston, VA 20191 Email: guido@cnri.reston.va.us, guido@python.org Position paper for the OMG-DARPA-MCC Workshop on Compositional Software Architecture in Monterey, California, January 6-8, 1998. Introduction Python is an advanced scripting language that is being used successfully to glue together large software components. It spans multiple platforms, mid...
...=0.7, atten=4) from Sound.Effects import echo This also loads the submodule echo, and makes it available without its package prefix, so it can be used as follows: echo.echofilter(input, output, delay=0.7, atten=4) from Sound.Effects.echo import echofilter Again, this loads the submodule echo, but this makes its function echofilter directly available: echofilter(input, output, delay=0.7, atten=4) Note that when using from package import item, the ...
...=0, stop=None): i = start while stop is None or i < stop: try: item = sequence[i] except IndexError: break yield (i, item) i += 1 This reduces the validity to only sequences (as opposed to all iterable collections), but has the advantage of making iterindexed(x, i, j) iterate over x[i:j] while reporting the index sequence range(i, j) -- not so easy otherwise. Th...
Debugging Reference Count Problems Warning This page stays here for historical reasons and it may contain outdated or incorrect information. Debugging Reference Count Problems From: Guido van Rossum <guido@CNRI.Reston.VA.US> To: python-list@cwi.nl Date: Wed, 27 May 1998 11:09:40 -0400 Mike Fletcher wrote a number of posts about debugging C code that bombs, probably because of reference count problems. His approach to debugging this problem seems typical, but I thin...
...== type(()) and len(v) == 2: (code, message) = v else: code = 0 message = v print "I/O Error: " + message + " (" + str(code) + ")" print This code understands that IOError is often raised with a tuple of the form (errorcode, message), and sometimes with just a string. However, since it explicitly tests for tuple-ness of the value, it will crash when the value is an instance! Again, the remedy is to just go ahead and try the tuple unpack, an...
Python Style Guide Python Style Guide Author: Guido van Rossum The style guide originally at this URL has been turned into two PEPs (Python Enhancement Proposals): PEP 8 for the main text, and PEP 257 for docstring conventions.
...= x + 1 #END If you are more familiar with C and C++ then you will be comfortable with either: if x: #{ x = x + 1 #} or: if x: x = x + 1 or even: if x: x = x + 1 C programmers will be happy to hear that the Python parser will do the right thing even if curly braces are not included when two trailing statements are present: if x: x = x + 1 y = 3 + x This last feature will fix a...
New-style Classes Warning New-style classes has been integrated into Python 2.7 and old-style classes has been removed in Python 3. Please refer to the Python tutorial and the Descriptor HowTo Guide for more up-to-date documentation about classes and descriptors respectively. Unfortunately, new-style classes have not yet been integrated into Python's standard documentation. Fear not, however; many people have worked to provide useful information on creating and using new-style classes: Unif...
Slideshow Collections for Instructional Use We are collecting and making available slideshows for reading at your own pace and reuse in your presentations. The preferred format is reStructuredText/S5 since it can be easily edited without special software and converted into various delivery formats. Where possible, speaker notes are included to give the slides meaning without an audio overlay. Preparing for Screencasting Advice on how to get started giving screencasts, why you might want to...
Python documentation by version Some previous versions of the documentation remain available online. Use the list below to select a version to view. For unreleased (in development) documentation, see In development versions. Python 3.14.0, documentation released on 7 October 2025. Python 3.13.9, documentation released on 14 October 2025. Python 3.13.8, documentation released on 7 October 2025. Python 3.13.7, documentation released on 14 August 2025. Python 3.13.6, documentation released on 6...
Python for Mac OS X Python for Mac OS X Python comes pre-installed on Mac OS X so it is easy to start using. However, to take advantage of the latest versions of Python, you will need to download and install newer versions alongside the system ones. The easiest way to do that is to install one of the binary installers for OS X from the Python Download page. Installers are available for the latest Python 3 and Python 2 releases that will work on all Macs that run Mac OS X 10.5 and later. Py...
IDLE and tkinter with Tcl/Tk on macOS Important If you are using macOS 12 Monterey or later, you may see problems with file open and save dialogs when using IDLE or other tkinter-based applications. The most recent versions of python.org installers (for 3.10.0 and 3.9.8) have patched versions of Tk to avoid these problems. They should be fixed in an upcoming Tk 8.6.12 release. If you are using a Python from any current python.org Python installer for macOS (3.10.0+ or 3.9.0+), no further acti...
Download Python for other platforms Python has been ported to a number of specialized and/or older platforms, listed below in alphabetical order. Note that these ports often lag well behind the latest Python release. Python for AIX AIX binary packages for Python are available from IBM AIX Toolbox in RPM format. They can be installed using dnf package manager. Visit the Get Started page for more details. Python for HP-UX You can purchase ActivePython (commercial and community versions, in...
Releases Python releases are now listed on the downloads page. This page only provides links to older releases which are not listed in the release database. Python 1.6.1 (September 2000) Python 1.5.2 (April 1999) Older source releases (1.0.1 - 1.6) Ancient source releases (pre 1.0) Python 1.5 binaries Python 1.4 binaries Python 1.3 binaries Python 1.2 binaries Python 1.1 binaries
Python 1.5.2 Python 1.5.2 Do yourself a favor and get a more recent version! On 13 April 1999, the final version of Python 1.5.2 was released: Python 1.5.2 sources (2.5 MB) Python 1.5.2 installer for Windows (5.0 MB) What's new in 1.5.2? Documentation (both online and downloadable) Note: the Python installer for Windows includes the Tcl/Tk 8.0.5 installer. See the Tkinter resource guide for troubleshooting the Tcl/Tk installation. Windows users may also be interested in Mark Hammond's win...
...==0. Latest re and pcre modules (versions of Dec. 22).
...== '1', which used to be '1L'; repr(1L) is unchanged and still returns '1L'. For floats, repr() now gives 17 digits of precision, to ensure no precision is lost (on all current hardware). The -X option is gone. Built-in exceptions are now always classes. Many more library modules also have been converted to class-based exceptions. Binary Incompatibilities Third party extensions built for Python 1.5.x cannot be used with Python 1.6; these extensions will have to b...
If you didn't find what you need, try your search in the Python language documentation.