2.2.6 Sequence Types

typeiter.html | types.html | string-methods.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 2.2.6 Sequence Types
There are six sequence types: strings, Unicode strings, lists,
tuples, buffers, and xrange objects.
Strings literals are written in single or double quotes:
`'xyzzy'`, `"frobozz"`. See chapter 2 of the
Python Reference Manual (../ref/strings.html) for more about
string literals. Unicode strings are much like strings, but are
specified in the syntax using a preceeding "u" character:
`u'abc'`, `u"def"`. Lists are constructed with square brackets,
separating items with commas: `[a, b, c]`. Tuples are
constructed by the comma operator (not within square brackets), with
or without enclosing parentheses, but an empty tuple must have the
enclosing parentheses, e.g., `a, b, c` or `()`. A single
item tuple must have a trailing comma, e.g., `(d,)`.
Buffer objects are not directly supported by Python syntax, but can be
created by calling the builtin function
buffer().. They don't support
concatenation or repetition.
Xrange objects are similar to buffers in that there is no specific
syntax to create them, but they are created using the xrange()
function. They don't support slicing,
concatenation or repetition, and using `in`, `not in`,
min() or max() on them is inefficient.
Most sequence types support the following operations. The "in" and
"not in" operations have the same priorities as the comparison
operations. The "+" and "*" operations have the same
priority as the corresponding numeric operations.2.7 (#foot1515)
This table lists the sequence operations sorted in ascending priority
(operations in the same box have the same priority). In the table,
s and t are sequences of the same type; n, i
and j are integers:
Notes:
(1): Values of n less than `0` are treated as
`0` (which yields an empty sequence of the same type as
s). Note also that the copies are shallow; nested structures
are not copied. This often haunts new Python programmers; consider:
```text

>>> lists = [[]] * 3
>>> lists
[[], [], []]
>>> lists[0].append(3)
>>> lists
[[3], [3], [3]]
```
What has happened is that `lists` is a list containing three
copies of the list `[[]]` (a one-element list containing an
empty list), but the contained list is shared by each copy. You can
create a list of different lists this way:
```text

>>> lists = [[] for i in range(3)]
>>> lists[0].append(3)
>>> lists[1].append(5)
>>> lists[2].append(7)
>>> lists
[[3], [5], [7]]
```
(2): If i or j is negative, the index is relative to
the end of the string: `len( s ) + i` or
`len( s ) + j` is substituted. But note that `-0` is
still `0`.
(3): The slice of s from i to j is defined as
the sequence of items with index k such that `i <= k < j`. If i or j is greater than
`len( s )`, use `len( s )`. If i is omitted,
use `0`. If j is omitted, use `len( s )`. If
i is greater than or equal to j, the slice is empty.
---
#### Footnotes


A. Undocumented Modules

module-winsound.html | lib.html | node613.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# A. Undocumented Modules
Here's a quick listing of modules that are currently undocumented, but
that should be documented. Feel free to contribute documentation for
them! (Send via email to python-docs@python.org.)
The idea and original contents for this chapter were taken
from a posting by Fredrik Lundh; the specific contents of this chapter
have been substantially revised.


5.3.3 Classes and functions

legacy-unit-tests.html | module-unittest.html | testcase-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 5.3.3 Classes and functions


8. Unix Specific Services

completer-objects.html | lib.html | module-posix.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
# 8. Unix Specific Services
The modules described in this chapter provide interfaces to features
that are unique to the Unix operating system, or in some cases to
some or many variants of it. Here's an overview:


11.5.19 UnknownHandler Objects

gopher-handler.html | module-urllib2.html | module-httplib.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.5.19 UnknownHandler Objects


11.3.2 Examples

urlopener-objs.html | module-urllib.html | module-urllib2.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.3.2 Examples
Here is an example session that uses the "GET" method to retrieve
a URL containing parameters:
```text

>>> import urllib
>>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
>>> f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query?%s" % params)
>>> print f.read()
```
The following example uses the "POST" method instead:


11.4.1 URLopener Objects

module-urllib.html | module-urllib.html | node307.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.4.1 URLopener Objects
URLopener and FancyURLopener objects have the
following attributes.
The FancyURLopener class offers one additional method that
should be overloaded to provide the appropriate behavior:


11.2.2 Using the cgi module

cgi-intro.html | module-cgi.html | node281.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.2.2 Using the cgi module
Begin by writing "import cgi". Do not use "from cgi import
*" -- the module defines all sorts of names for its own use or for
backward compatibility that you don't want in your namespace.
It's best to use the FieldStorage class. The other classes
defined in this module are provided mostly for backward compatibility.
Instantiate it exactly once, without arguments. This reads the form
contents from standard input or the environment (depending on the
value of various environment variables set according to the CGI
standard). Since it may consume standard input, it should be
instantiated only once.
The FieldStorage instance can be indexed like a Python
dictionary, and also supports the standard dictionary methods
has_key() and keys().
Form fields containing empty strings are ignored
and do not appear in the dictionary; to keep such values, provide
the optional "keep_blank_values" argument when creating the
FieldStorage instance.
For instance, the following code (which assumes that the
`Content-Type` header and blank line have already been printed)
checks that the fields `name` and `addr` are both set to a
non-empty string:
```text

form = cgi.FieldStorage()
form_ok = 0
if form.has_key("name") and form.has_key("addr"):
form_ok = 1
if not form_ok:
print "<H1>Error</H1>"
print "Please fill in the name and addr fields."
return
print "<p>name:", form["name"].value
print "<p>addr:", form["addr"].value
...further form processing here...
```
Here the fields, accessed through "form[key]", are
themselves instances of FieldStorage (or
MiniFieldStorage, depending on the form encoding).
The value attribute of the instance yields the string value
of the field. The getvalue() method returns this string value
directly; it also accepts an optional second argument as a default to
return if the requested key is not present.
If the submitted form data contains more than one field with the same
name, the object retrieved by "form[key]" is not a
FieldStorage or MiniFieldStorage
instance but a list of such instances. Similarly, in this situation,
"form.getvalue(key)" would return a list of strings.
If you expect this possibility
(i.e., when your HTML form contains multiple fields with the same
name), use the type() function to determine whether you
have a single instance or a list of instances. For example, here's
code that concatenates any number of username fields, separated by
commas:
```text

value = form.getvalue("username", "")
if type(value) is type([]):
# Multiple username fields specified
usernames = ",".join(value)
else:
# Single or no username field specified
usernames = value
```
If a field represents an uploaded file, accessing the value via the
value attribute or the getvalue() method reads the
entire file in memory as a string. This may not be what you want.
You can test for an uploaded file by testing either the filename
attribute or the file attribute. You can then read the data at
leisure from the file attribute:
```text

fileitem = form["userfile"]
if fileitem.file:
# It's an uploaded file; count lines
linecount = 0
while 1:
line = fileitem.file.readline()
if not line: break
linecount = linecount + 1
```
The file upload draft standard entertains the possibility of uploading
multiple files from one field (using a recursive
multipart/* encoding). When this occurs, the item will be
a dictionary-like FieldStorage item. This can be determined
by testing its type attribute, which should be
multipart/form-data (or perhaps another MIME type matching
multipart/*). In this case, it can be iterated over
recursively just like the top-level form object.
When a form is submitted in the ``old'' format (as the query string or
as a single data part of type
application/x-www-form-urlencoded), the items will actually
be instances of the class MiniFieldStorage. In this case, the
list, file, and filename attributes are
always `None`.


3.20.1 Warning Categories

module-warnings.html | module-warnings.html | warning-filter.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.20.1 Warning Categories
There are a number of built-in exceptions that represent warning
categories. This categorization is useful to be able to filter out
groups of warnings. The following warnings category classes are
currently defined:
While these are technically built-in exceptions, they are documented
here, because conceptually they belong to the warnings mechanism.
User code can define additional warning categories by subclassing one
of the standard warning categories. A warning category must always be
a subclass of the Warning class.


3.20.2 The Warnings Filter

warning-categories.html | module-warnings.html | warning-functions.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.20.2 The Warnings Filter
The warnings filter controls whether warnings are ignored, displayed,
or turned into errors (raising an exception).
Conceptually, the warnings filter maintains an ordered list of filter
specifications; any specific warning is matched against each filter
specification in the list in turn until a match is found; the match
determines the disposition of the match. Each entry is a tuple of the
form (action, message, category, module,
lineno), where:
- action is one of the following strings:
- message is a compiled regular expression that the warning
message must match (the match is case-insensitive)
- category is a class (a subclass of Warning) of
which the warning category must be a subclass in order to match
- module is a compiled regular expression that the module
name must match
- lineno is an integer that the line number where the
warning occurred must match, or `0` to match all line
numbers
Since the Warning class is derived from the built-in
Exception class, to turn a warning into an error we simply
raise `category(message)`.
The warnings filter is initialized by -W options passed
to the Python interpreter command line. The interpreter saves the
arguments for all -W options without interpretation in
`sys.warnoptions`; the warnings module parses these when
it is first imported (invalid options are ignored, after printing a
message to `sys.stderr`).


3.20.3 Available Functions

warning-filter.html | module-warnings.html | module-imp.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.20.3 Available Functions


14.5.1 Wave_read Objects

module-wave.html | module-wave.html | Wave-write-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 14.5.1 Wave_read Objects
Wave_read objects, as returned by open(), have the
following methods:
The following two methods are defined for compatibility with the
aifc (module-aifc.html) module, and don't do anything interesting.
The following two methods define a term ``position'' which is compatible
between them, and is otherwise implementation dependent.


14.5.2 Wave_write Objects

Wave-read-objects.html | module-wave.html | module-chunk.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 14.5.2 Wave_write Objects
Wave_write objects, as returned by open(), have the
following methods:


3.3.2 Example

weakref-objects.html | module-weakref.html | weakref-extension.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.3.2 Example
This simple example shows how an application can use objects IDs to
retrieve objects that it has seen before. The IDs of the objects can
then be used in other data structures without forcing the objects to
remain alive, but the objects can still be retrieved by ID if they
do.
```text

import weakref

_id2obj_dict = weakref.WeakValueDictionary()

def remember(obj):
oid = id(obj)
_id2obj_dict[oid] = obj
return oid

def id2obj(oid):
return _id2obj_dict[oid]
```


weakref-example.html | module-weakref.html | module-fpectl.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.3.3 Weak References in Extension Types
One of the goals of the implementation is to allow any type to
participate in the weak reference mechanism without incurring the
overhead on those objects which do not benefit by weak referencing
(such as numbers).
For an object to be weakly referencable, the extension must include a
PyObject* field in the instance structure for the use of the
weak reference mechanism; it must be initialized to NULL by the
object's constructor. It must also set the tp_weaklistoffset
field of the corresponding type object to the offset of the field.
For example, the instance type is defined with the following structure:
```text

typedef struct {
PyObject_HEAD
PyClassObject *in_class; /* The class object */
PyObject *in_dict; /* A dictionary */
PyObject *in_weakreflist; /* List of weak references */
} PyInstanceObject;
```
The statically-declared type object for instances is defined this way:
```text

PyTypeObject PyInstance_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
"module.instance",

/* Lots of stuff omitted for brevity... */

offsetof(PyInstanceObject, in_weakreflist) /* tp_weaklistoffset */
};
```
The only further addition is that the destructor needs to call the
weak reference manager to clear any weak references. This should be
done before any other parts of the destruction have occurred, but is
only required if the weak reference list is non-NULL:


3.3.1 Weak Reference Objects

module-weakref.html | module-weakref.html | weakref-example.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 3.3.1 Weak Reference Objects
Weak reference objects have no attributes or methods, but do allow the
referent to be obtained, if it still exists, by calling it:
```text

>>> import weakref
>>> class Object:
... pass
...
>>> o = Object()
>>> r = weakref.ref(o)
>>> o2 = r()
>>> o is o2
1
```
If the referent no longer exists, calling the reference object returns
`None`:
```text

>>> del o, o2
>>> print r()
None
```
Testing that a weak reference object is still live should be done
using the expression `ref () is not None`. Normally,
application code that needs to use a reference object should follow
this pattern:
```text

# r is a weak reference object
o = r()
if o is None:
# referent has been garbage collected
print "Object has been allocated; can't frobnicate."
else:
print "Object is still live!"
o.do_something_useful()
```
Using a separate test for ``liveness'' creates race conditions in
threaded applications; another thread can cause a weak reference to
become invalidated before the weak reference is called; the
idiom shown above is safe in threaded applications as well as
single-threaded applications.


12.1.4 Writer Implementations

writer-interface.html | module-formatter.html | module-email.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.1.4 Writer Implementations
Three implementations of the writer object interface are provided as
examples by this module. Most applications will need to derive new
writer classes from the NullWriter class.


12.1.3 The Writer Interface

formatter-impls.html | module-formatter.html | writer-impls.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.1.3 The Writer Interface
Interfaces to create writers are dependent on the specific writer
class being instantiated. The interfaces described below are the
required interfaces which all writers must support once initialized.
Note that while most applications can use the
AbstractFormatter class as a formatter, the writer must
typically be provided by the application.


12.17.3 Exceptions

xdr-unpacker-objects.html | module-xdrlib.html | module-netrc.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.17.3 Exceptions
Exceptions in this module are coded as class instances:
Here is an example of how you would catch one of these exceptions:
```text

import xdrlib
p = xdrlib.Packer()
try:
p.pack_double(8.01)
except xdrlib.ConversionError, instance:
print 'packing the double failed:', instance.msg
```


12.17.1 Packer Objects

module-xdrlib.html | module-xdrlib.html | xdr-unpacker-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.17.1 Packer Objects
Packer instances have the following methods:
In general, you can pack any of the most common XDR data types by
calling the appropriate `pack_ type ()` method. Each method
takes a single argument, the value to pack. The following simple data
type packing methods are supported: pack_uint(),
pack_int(), pack_enum(), pack_bool(),
pack_uhyper(), and pack_hyper().
The following methods support packing strings, bytes, and opaque data:
The following methods support packing arrays and lists:


12.17.2 Unpacker Objects

xdr-packer-objects.html | module-xdrlib.html | xdr-exceptions.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 12.17.2 Unpacker Objects
The Unpacker class offers the following methods:
In addition, every data type that can be packed with a Packer,
can be unpacked with an Unpacker. Unpacking methods are of the
form `unpack_ type ()`, and take no arguments. They return the
unpacked object.
In addition, the following methods unpack strings, bytes, and opaque
data:
The following methods support unpacking arrays and lists:


13.13.1 XML Namespaces

module-xmllib.html | module-xmllib.html | mmedia.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.13.1 XML Namespaces
This module has support for XML namespaces as defined in the XML
Namespaces proposed recommendation.
Tag and attribute names that are defined in an XML namespace are
handled as if the name of the tag or element consisted of the
namespace (the URL that defines the namespace) followed by a
space and the name of the tag or attribute. For instance, the tag
`<html xmlns='http://www.w3.org/TR/REC-html40'>` is treated as if
the tag name was `'http://www.w3.org/TR/REC-html40 html'`, and
the tag `<html:a href='http://frob.com'>` inside the above
mentioned element is treated as if the tag name were
`'http://www.w3.org/TR/REC-html40 a'` and the attribute name as
if it were `'http://www.w3.org/TR/REC-html40 href'`.
An older draft of the XML Namespaces proposal is also recognized, but
triggers a warning.
See Also:


13.5.1 XMLParser Objects

module-xml.parsers.expat.html | module-xml.parsers.expat.html | expaterror-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.5.1 XMLParser Objects
xmlparser objects have the following methods:
xmlparser objects have the following attributes:
The following attributes contain values relating to the most recent
error encountered by an xmlparser object, and will only have
correct values once a call to Parse() or ParseFile()
has raised a xml.parsers.expat.ExpatError exception.
Here is the list of handlers that can be set. To set a handler on an
xmlparser object o, use
`o . handlername = func`. handlername must
be taken from the following list, and func must be a callable
object accepting the correct number of arguments. The arguments are
all strings, unless otherwise stated.


13.12.1 XMLReader Objects

module-xml.sax.xmlreader.html | module-xml.sax.xmlreader.html | incremental-parser-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 13.12.1 XMLReader Objects
The XMLReader interface supports the following methods:


11.20.8 Example of Client Usage

node365.html | module-xmlrpclib.html | module-SimpleXMLRPCServer.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 11.20.8 Example of Client Usage


7.15.1 ZipFile Objects

module-zipfile.html | module-zipfile.html | pyzipfile-objects.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 7.15.1 ZipFile Objects
The following data attribute is also available:


7.15.3 ZipInfo Objects

pyzipfile-objects.html | module-zipfile.html | module-readline.html | Python Library Reference | contents.html | modindex.html | genindex.html
---
## 7.15.3 ZipInfo Objects
Instances of the ZipInfo class are returned by the
getinfo() and infolist() methods of
ZipFile objects. Each object stores information about a
single member of the ZIP archive.
Instances have the following attributes:


About this document ...

genindex.html | mac.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# About this document ...
Macintosh Library Modules,
December 21, 2001, Release 2.2
This document was generated using the LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) translator.
LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) is Copyright ©
1993, 1994, 1995, 1996, 1997, Nikos
Drakos (http://cbl.leeds.ac.uk/nikos/personal.html), Computer Based Learning Unit, University of
Leeds, and Copyright © 1997, 1998, Ross
Moore (http://www.maths.mq.edu.au/~ross/), Mathematics Department, Macquarie University,
Sydney.
The application of LaTeX2HTML (http://saftsack.fs.uni-bayreuth.de/~latex2ht/) to the Python
documentation has been heavily tailored by Fred L. Drake,
Jr. Original navigation icons were contributed by Christopher
Petrilli.
---
## Comments and Questions
General comments and questions regarding this document should
be sent by email to python-docs@python.org (mailto:python-docs@python.org). If you find specific errors in
this document, please report the bug at the Python Bug
Tracker (http://sourceforge.net/bugs/?group_id=5470) at SourceForge (http://sourceforge.net/).
Questions regarding how to use the information in this
document should be sent to the Python news group, comp.lang.python (news:comp.lang.python), or the Python mailing list (http://www.python.org/mailman/listinfo/python-list) (which is gated to the newsgroup and
carries the same content).
For any of these channels, please be sure not to send HTML email.
Thanks.
---
genindex.html | mac.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
Release 2.2, documentation updated on December 21, 2001.


2.12.1 AEServer Objects

module-MiniAEFrame.html | module-MiniAEFrame.html | module-aepack.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.12.1 AEServer Objects


2.4.2 Alias Objects

fsspec-objects.html | module-macfs.html | finfo-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.4.2 Alias Objects
Note that it is currently not possible to directly manipulate a
resource as an Alias object. Hence, after calling
Update() or after Resolve() indicates that the alias
has changed the Python program is responsible for getting the
data value from the Alias object and modifying the
resource.


2.11.1 Application Objects

module-FrameWork.html | module-FrameWork.html | window-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.11.1 Application Objects
Application objects have the following methods, among others:


1.4 Simulating command line arguments

creator-code.html | using.html | node10.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.4 Simulating command line arguments
There are two ways to simulate command-line arguments with MacPython.
1. via Interpreter options
- Hold the option-key down when launching your script. This will
bring up a dialog box of Python Interpreter options.
- Click ``Set Unix-style command line..'' button.
- Type the arguments into the ``Argument'' field.
- Click ``OK''
- Click ``Run''.
2. via drag and drop
If you save the script as an applet (see Section 1.6.4 (IDEapplet.html#IDEapplet)), you
can also simulate some command-line arguments via
``Drag-and-Drop''. In this case, the names of the files that were
dropped onto the applet will be appended to `sys.argv`, so that
it will appear to the script as though they had been typed on a
command line. As on Unix systems, the first item in `sys.srgv` is
the path to the applet, and the rest are the files dropped on the
applet.


1.7 Configuration

IDEapplet.html | using.html | EditPythonPrefs.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.7 Configuration
The MacPython distribution comes with EditPythonPrefs, an
applet which will help you to customize the MacPython environment for
your working habits.


2.3.1 Connection Objects

module-ctb.html | module-ctb.html | module-macfs.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.3.1 Connection Objects
For all connection methods that take a timeout argument, a value
of `-1` is indefinite, meaning that the command runs to completion.


Contents

front.html | mac.html | using.html | Macintosh Library Modules | modindex.html | genindex.html
---
## Contents
Table of Contents
- Front Matter (front.html)
  1. Using Python on the Macintosh (using.html)
  - 1.1 Getting and Installing MacPython (getting.html)
  1.2 Entering the interactive Interpreter (interpreter.html)
  1.3 How to run a Python script (node6.html)
  - 1.3.1 Drag and drop (node7.html)
  1.3.2 Set Creator and Double Click (creator-code.html)
  1.4 Simulating command line arguments (argv.html)
  1.5 Creating a Python script (node10.html)
  - 1.5.1 In an editor (node11.html)
  1.6 The IDE (IDE.html)
  - 1.6.1 Using the ``Python Interactive'' window (node15.html)
  1.6.2 Writing a Python Script (IDEwrite.html)
  1.6.3 Executing a script from within the IDE (IDEexecution.html)
  1.6.4 ``Save as'' versus ``Save as Applet'' (IDEapplet.html)
  1.7 Configuration (configuration.html)
  - 1.7.1 EditPythonPrefs (EditPythonPrefs.html)
  1.7.2 Adding modules to the Module Search Path (search-path.html)
  1.7.3 Default startup options (defaults.html)
  1.8 Mac OS X (node23.html)
  2. MacPython Modules (macpython-modules.html)
  - 2.1 mac -- Implementations for the os module (module-mac.html)
  2.2 macpath -- MacOS path manipulation functions (module-macpath.html)
  2.3 ctb -- Interface to the Communications Tool Box (module-ctb.html)
  - 2.3.1 Connection Objects (connection-object.html)
  2.4 macfs -- Various file system services (module-macfs.html)
  - 2.4.1 FSSpec objects (fsspec-objects.html)
  2.4.2 Alias Objects (alias-objects.html)
  2.4.3 FInfo Objects (finfo-objects.html)
  2.5 ic -- Access to Internet Config (module-ic.html)
  - 2.5.1 IC Objects (node34.html)
  2.6 MacOS -- Access to Mac OS interpreter features (module-MacOS.html)
  2.7 macostools -- Convenience routines for file manipulation (module-macostools.html)
  2.8 findertools -- The finder's Apple Events interface (module-findertools.html)
  2.9 macspeech -- Interface to the Macintosh Speech Manager (module-macspeech.html)
  - 2.9.1 Voice Objects (voice-objects.html)
  2.9.2 Speech Channel Objects (speech-channel-objects.html)
  2.10 EasyDialogs -- Basic Macintosh dialogs (module-EasyDialogs.html)
  2.11 FrameWork -- Interactive application framework (module-FrameWork.html)
  - 2.11.1 Application Objects (application-objects.html)
  2.11.2 Window Objects (window-objects.html)
  2.11.3 ControlsWindow Object (controlswindow-object.html)
  2.11.4 ScrolledWindow Object (scrolledwindow-object.html)
  2.11.5 DialogWindow Objects (dialogwindow-objects.html)
  2.12 MiniAEFrame -- Open Scripting Architecture server support (module-MiniAEFrame.html)
  - 2.12.1 AEServer Objects (aeserver-objects.html)
  2.13 aepack -- Conversion between Python variables and AppleEvent data containers (module-aepack.html)
  2.14 aetypes -- AppleEvent objects (module-aetypes.html)
  3. MacOS Toolbox Modules (toolbox.html)
  - 3.1 Carbon.AE -- Apple Events (module-Carbon.AE.html)
  3.2 Carbon.App -- Appearance Manager (module-Carbon.App.html)
  3.3 Carbon.CF -- Core Foundation (module-Carbon.CF.html)
  3.4 Carbon.Cm -- Component Manager (module-Carbon.Cm.html)
  3.5 Carbon.Ctl -- Control Manager (module-Carbon.Ctl.html)
  3.6 Carbon.Dlg -- Dialog Manager (module-Carbon.Dlg.html)
  3.7 Carbon.Evt -- Event Manager (module-Carbon.Evt.html)
  3.8 Carbon.Fm -- Font Manager (module-Carbon.Fm.html)
  3.9 Carbon.Help -- Help Manager (module-Carbon.Help.html)
  3.10 Carbon.List -- List Manager (module-Carbon.List.html)
  3.11 Carbon.Menu -- Menu Manager (module-Carbon.Menu.html)
  3.12 Carbon.Mlte -- MultiLingual Text Editor (module-Carbon.Mlte.html)
  3.13 Carbon.Qd -- QuickDraw (module-Carbon.Qd.html)
  3.14 Carbon.Qdoffs -- QuickDraw Offscreen (module-Carbon.Qdoffs.html)
  3.15 Carbon.Qt -- QuickTime (module-Carbon.Qt.html)
  3.16 Carbon.Res -- Resource Manager and Handles (module-Carbon.Res.html)
  3.17 Carbon.Scrap -- Scrap Manager (module-Carbon.Scrap.html)
  3.18 Carbon.Snd -- Sound Manager (module-Carbon.Snd.html)
  3.19 Carbon.TE -- TextEdit (module-Carbon.TE.html)
  3.20 Carbon.Win -- Window Manager (module-Carbon.Win.html)
  3.21 ColorPicker -- Color selection dialog (module-ColorPicker.html)
  4. Undocumented Modules (undocumented-modules.html)
  - 4.1 applesingle -- AppleSingle decoder (module-applesingle.html)
  4.2 buildtools -- Helper module for BuildApplet and Friends (module-buildtools.html)
  4.3 py_resource -- Resources from Python code (module-pyresource.html)
  4.4 cfmfile -- Code Fragment Resource module (module-cfmfile.html)
  4.5 icopen -- Internet Config replacement for open() (module-icopen.html)
  4.6 macerrors -- Mac OS Errors (module-macerrors.html)
  4.7 macfsn -- NavServices calls (module-macfsn.html)
  4.8 macresource -- Locate script resources (module-macresource.html)
  4.9 Nav -- NavServices calls (module-Nac.html)
  4.10 mactty -- Serial line connections (module-mactty.html)
  4.11 mkcwproject -- Create CodeWarrior projects (module-mkcwproject.html)
  4.12 nsremote -- Wrapper around Netscape OSA modules (module-nsremote.html)
  4.13 PixMapWrapper -- Wrapper for PixMap objects (module-PixMapWrapper.html)
  4.14 preferences -- Application preferences manager (module-preferences.html)
  4.15 pythonprefs -- Preferences manager for Python (module-pythonprefs.html)
  4.16 quietconsole -- non-visible stdout output (module-quietconsole.html)
  4.17 videoreader -- read QuickTime movies (module-videoreader.html)
  4.18 W -- Widgets built on FrameWork (module-W.html)
  4.19 waste -- non-Apple TextEdit replacement (module-waste.html)
  A. History and License (node94.html)
  - A.1 History of the software (node95.html)
  A.2 Terms and conditions for accessing or otherwise using Python (node96.html)
  Module Index (modindex.html)
  About this document ... (about.html)
End of Table of Contents


2.11.3 ControlsWindow Object

window-objects.html | module-FrameWork.html | scrolledwindow-object.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.11.3 ControlsWindow Object
ControlsWindow objects have the following methods besides those of
`Window` objects:


1.3.2 Set Creator and Double Click

node7.html | node6.html | argv.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.3.2 Set Creator and Double Click
If the script that you want to launch has the appropriate Creator Code
and File Type you can simply double-click on the script to launch it.
To be ``double-clickable'' a file needs to be of type "TEXT",
with a creator code of "Pyth".
Setting the creator code and filetype can be done with the IDE (see
sections 1.6.2 (node16.html#IDEwrite) and 1.6.4 (IDEapplet.html#IDEapplet)), with an editor with a
Python mode (BBEdit) - see section
1.5.1 (scripting-with-BBedit.html#scripting-with-BBedit), or with assorted other Mac utilities, but
a script (fixfiletypes.py) has been included in the MacPython
distribution, making it possible to set the proper Type and Creator
Codes with Python.
The fixfiletypes.py script will change the file type and
creator codes for the indicated directory. To use
fixfiletypes.py:
1. Locate it in the scripts folder of the Mac folder of the
MacPython distribution.
2. Put all of the scripts that you want to fix in a folder with nothing
else in it.
3. Double-click on the fixfiletypes.py icon.
4. Navigate into the folder of files you want to fix, and press the
``Select current folder'' button.


1.7.3 Default startup options

search-path.html | configuration.html | node23.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.7.3 Default startup options
The ``Default startup options...'' button in the
EditPythonPrefs dialog box gives you many options including
the ability to keep the ``Output'' window open after the script
terminates, and the ability to enter interactive mode after the
termination of the run script. The latter can be very helpful if you
want to examine the objects that were created during your script.


2.11.5 DialogWindow Objects

scrolledwindow-object.html | module-FrameWork.html | module-MiniAEFrame.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.11.5 DialogWindow Objects
DialogWindow objects have the following methods besides those of
`Window` objects:


2.4.1 DNR Result Objects

module-macdnr.html | module-macdnr.html | module-macfs.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.4.1 DNR Result Objects
Since the DNR calls all execute asynchronously you do not get the
results back immediately. Instead, you get a dnr result object. You
can check this object to see whether the query is complete, and access
its attributes to obtain the information when it is.
Alternatively, you can also reference the result attributes directly,
this will result in an implicit wait for the query to complete.
The rtnCode and cname attributes are always
available, the others depend on the type of query (address, hinfo or
mx).
The simplest way to use the module to convert names to dotted-decimal
strings, without worrying about idle time, etc:


1.7.1 EditPythonPrefs

configuration.html | configuration.html | search-path.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.7.1 EditPythonPrefs
EditPythonPrefs gives you the capability to configure Python
to behave the way you want it to. There are two ways to use
EditPythonPrefs, you can use it to set the preferences in
general, or you can drop a particular Python engine onto it to
customize only that version. The latter can be handy if, for example,
you want to have a second copy of the PythonInterpreter that
keeps the output window open on a normal exit even though you prefer
to normally not work that way.
To change the default preferences, simply double-click on
EditPythonPrefs. To change the preferences only for one copy
of the Interpreter, drop the icon for that copy onto
EditPythonPrefs. You can also use EditPythonPrefs
in this fashion to set the preferences of the Python IDE and
any applets you create - see section 1.6.4 (IDEapplet.html#IDEapplet).


2.4.3 FInfo Objects

alias-objects.html | module-macfs.html | module-ic.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.4.3 FInfo Objects
See Inside Macintosh: Files for a complete description of what
the various fields mean.


Front Matter

mac.html | mac.html | contents.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# Front Matter
Copyright © 2001 Python Software Foundation.
All rights reserved.
Copyright © 2000 BeOpen.com.
All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives.
All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum.
All rights reserved.
See the end of this document for complete license and permissions
information.
### Abstract:
This library reference manual documents Python's extensions for the
Macintosh. It should be used in conjunction with the
Python Library Reference (../lib/lib.html), which documents
the standard library and built-in types.
This manual assumes basic knowledge about the Python language. For an
informal introduction to Python, see the
Python Tutorial (../tut/tut.html); the
Python Reference Manual (../ref/ref.html) remains the
highest authority on syntactic and semantic questions. Finally, the
manual entitled Extending and Embedding
the Python Interpreter (../ext/ext.html) describes how to add new extensions to Python
and how to embed it in other applications.


2.4.1 FSSpec objects

module-macfs.html | module-macfs.html | alias-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.4.1 FSSpec objects


Index

modindex.html | mac.html | about.html | Macintosh Library Modules | contents.html | modindex.html
---
## Index
---
_ (#letter-_) |
a (#letter-a) |
b (#letter-b) |
c (#letter-c) |
d (#letter-d) |
e (#letter-e) |
f (#letter-f) |
g (#letter-g) |
h (#letter-h) |
i (#letter-i) |
l (#letter-l) |
m (#letter-m) |
n (#letter-n) |
o (#letter-o) |
p (#letter-p) |
q (#letter-q) |
r (#letter-r) |
s (#letter-s) |
t (#letter-t) |
u (#letter-u) |
v (#letter-v) |
w (#letter-w) |
x (#letter-x)
---
## _ (underscore)
---
## A
---
## B
---
## C
---
## D
---
## E
---
## F
---
## G
---
## H
---
## I
---
## L
---
## M
---
## N
---
## O
---
## P
---
## Q
---
## R
---
## S
---
## T
---
## U
---
## V
---
## W
---
## X


1.1 Getting and Installing MacPython

using.html | using.html | interpreter.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.1 Getting and Installing MacPython
The most recent release version as well as possible newer experimental
versions are best found at the MacPython page maintained by Jack
Jansen: http://www.cwi.nl/~jack/macpython.html.
Please refer to the README included with your distribution for
the most up-to-date instructions.


1.6 The IDE

scripting-with-BBedit.html | using.html | node15.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.6 The IDE
The Python IDE (Integrated Development Environment) is a
separate application that acts as a text editor for your Python code,
a class browser, a graphical debugger, and more.


IDEexecution.html | IDE.html | configuration.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.6.4 ``Save as'' versus ``Save as Applet''
When you are done writing your Python script you have the option of
saving it as an ``applet'' (by selecting ``Save as applet'' from the
``File'' menu). This has a significant advantage in that you can drop
files or folders onto it, to pass them to the applet the way
command-line users would type them onto the command-line to pass them
as arguments to the script. However, you should make sure to save the
applet as a separate file, do not overwrite the script you are
writing, because you will not be able to edit it again.
Accessing the items passed to the applet via ``drag-and-drop'' is done
using the standard sys.argv mechanism. See the general
documentation for more
Note that saving a script as an applet will not make it runnable on a
system without a Python installation.


IDEwrite.html | IDE.html | IDEapplet.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.6.3 Executing a script from within the IDE
You can run the script in the frontmost window of the Python
IDE by hitting the run all button. You should be aware, however that
if you use the Python convention "if __name__ == "__main__":" the
script will not be ``__main__'' by default. To get that
behaviour you must select the ``Run as __main__'' option from the
small black triangle on the top right of the document window. Note
that this option is associated with the file not the
application. It will stay active after a save, however; to shut
this feature off simply select it again.


1.6.2 Writing a Python Script

node15.html | IDE.html | IDEexecution.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.6.2 Writing a Python Script
In addition to using the Python IDE interactively, you can
also type out a complete Python program, saving it incrementally, and
execute it or smaller selections of it.
You can create a new script, open a previously saved script, and save
your currently open script by selecting the appropriate item in the
``File'' menu. Dropping a Python script onto the
Python IDE will open it for editting.
If you try to open a script with the Python IDE but either
can't locate it from the ``Open'' dialog box, or you get an error
message like ``Can't open file of type ...'' see section
1.3.2 (creator-code.html#creator-code).
When the Python IDE saves a script, it uses the creator code
settings which are available by clicking on the small black triangle
on the top right of the document window, and selecting ``save
options''. The default is to save the file with the Python
IDE as the creator, this means that you can open the file for editing
by simply double-clicking on its icon. You might want to change this
behaviour so that it will be opened by the
PythonInterpreter, and run. To do this simply choose
``Python Interpreter'' from the ``save options''. Note that these
options are associated with the file not the application.


Macintosh Library Modules

../index.html | front.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# Macintosh Library Modules
Guido van Rossum
Fred L. Drake, Jr., editor
PythonLabs
Email: python-docs@python.org
Release 2.2
December 21, 2001


getting.html | using.html | node6.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.2 Entering the interactive Interpreter
The interactive interpreter that you will see used in Python
documentation is started by double-clicking the
PythonInterpreter icon, which looks like a 16-ton weight
falling. You should see the version information and the
">`>`> " prompt. Use it exactly as described in the
standard documentation.


Macintosh Library Modules


2. MacPython Modules

node23.html | mac.html | module-mac.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2. MacPython Modules
The following modules are only available on the Macintosh, and are
documented here:
mac (module-mac.html) | Implementations for the os module.
macpath (module-macpath.html) | MacOS path manipulation functions.
ctb (module-ctb.html) | Interfaces to the Communications Tool Box. Only the
Connection Manager is supported.
macfs (module-macfs.html) | Support for FSSpec, the Alias Manager,
finder aliases, and the Standard File package.
ic (module-ic.html) | Access to Internet Config.
MacOS (module-MacOS.html) | Access to Mac OS-specific interpreter features.
macostools (module-macostools.html) | Convenience routines for file manipulation.
findertools (module-findertools.html) | Wrappers around the finder's Apple Events interface.
macspeech (module-macspeech.html) | Interface to the Macintosh Speech Manager.
EasyDialogs (module-EasyDialogs.html) | Basic Macintosh dialogs.
FrameWork (module-FrameWork.html) | Interactive application framework.
MiniAEFrame (module-MiniAEFrame.html) | Support to act as an Open Scripting Architecture (OSA) server
(``Apple Events'').
aepack (module-aepack.html) | Conversion between Python variables and AppleEvent
data containers.
aetypes (module-aetypes.html) | Python representation of the Apple Event Object Model.


Module Index

node96.html | mac.html | genindex.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## Module Index
This index only lists modules documented in this manual.
The Global Module
Index (../modindex.html) lists all modules that are documented in this set
of manuals.
Some module names are followed by an annotation indicating what
platform they are available on.


3.1 AE -- Apple Events

toolbox.html | toolbox.html | module-Cm.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.1 AE -- Apple Events
Availability: Macintosh.


aeserver-objects.html | macpython-modules.html | module-aetypes.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.13 aepack --
Conversion between Python variables and AppleEvent data containers
Availability: Macintosh.
The aepack module defines functions for converting (packing)
Python variables to AppleEvent descriptors and back (unpacking).
Within Python the AppleEvent descriptor is handled by Python objects
of built-in type AEDesc, defined in module AE (module-AE.html).
The aepack module defines the following functions:


2.14 aetypes -- AppleEvent objects

module-aepack.html | macpython-modules.html | toolbox.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.14 aetypes --
AppleEvent objects
Availability: Macintosh.
The aetypes defines classes used to represent Apple Event
object specifiers. An object specifier is essentially an address of an
object implemented in a Apple Event server. An Apple Event specifier
is used as the direct object for an Apple Event or as the argument of
an optional parameter. In AppleScript an object specifier is
represented by a phrase such as:
`character 23 of document "Semprini"`. The classes defined in
this module allow this specifier to be represented by a Python object
which is initialized as follows:
`res = Document(1).Character(23)`
The AEObjects module defines the following class:


4.1 applesingle -- AppleSingle decoder

undocumented-modules.html | undocumented-modules.html | module-buildtools.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.1 applesingle -- AppleSingle decoder
Availability: Macintosh.


module-applesingle.html | undocumented-modules.html | module-pyresource.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.2 buildtools -- Helper module for BuildApplet and Friends
Availability: Macintosh.


3.1 Carbon.AE -- Apple Events

toolbox.html | toolbox.html | module-Carbon.App.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.1 Carbon.AE -- Apple Events
Availability: Macintosh.


3.2 Carbon.App -- Appearance Manager

module-Carbon.AE.html | toolbox.html | module-Carbon.CF.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.2 Carbon.App -- Appearance Manager
Availability: Macintosh.


3.3 Carbon.CF -- Core Foundation

module-Carbon.App.html | toolbox.html | module-Carbon.Cm.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.3 Carbon.CF -- Core Foundation
Availability: Macintosh.
This module is only available under Carbon MacPython. The
`CFBase`, `CFArray`, `CFData`, `CFDictionary`,
`CFString` and `CFURL` objects are supported, some
only partially.


3.4 Carbon.Cm -- Component Manager

module-Carbon.CF.html | toolbox.html | module-Carbon.Ctl.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.4 Carbon.Cm -- Component Manager
Availability: Macintosh.


3.5 Carbon.Ctl -- Control Manager

module-Carbon.Cm.html | toolbox.html | module-Carbon.Dlg.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.5 Carbon.Ctl -- Control Manager
Availability: Macintosh.


3.6 Carbon.Dlg -- Dialog Manager

module-Carbon.Ctl.html | toolbox.html | module-Carbon.Evt.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.6 Carbon.Dlg -- Dialog Manager
Availability: Macintosh.


3.7 Carbon.Evt -- Event Manager

module-Carbon.Dlg.html | toolbox.html | module-Carbon.Fm.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.7 Carbon.Evt -- Event Manager
Availability: Macintosh.


3.8 Carbon.Fm -- Font Manager

module-Carbon.Evt.html | toolbox.html | module-Carbon.Help.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.8 Carbon.Fm -- Font Manager
Availability: Macintosh.


3.9 Carbon.Help -- Help Manager

module-Carbon.Fm.html | toolbox.html | module-Carbon.List.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.9 Carbon.Help -- Help Manager
Availability: Macintosh.
This module is only available under MacOS9 and earlier in
classic PPC MacPython.


3.10 Carbon.List -- List Manager

module-Carbon.Help.html | toolbox.html | module-Carbon.Menu.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.10 Carbon.List -- List Manager
Availability: Macintosh.


3.11 Carbon.Menu -- Menu Manager

module-Carbon.List.html | toolbox.html | module-Carbon.Mlte.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.11 Carbon.Menu -- Menu Manager
Availability: Macintosh.


module-Carbon.Menu.html | toolbox.html | module-Carbon.Qd.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.12 Carbon.Mlte -- MultiLingual Text Editor
Availability: Macintosh.


3.13 Carbon.Qd -- QuickDraw

module-Carbon.Mlte.html | toolbox.html | module-Carbon.Qdoffs.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.13 Carbon.Qd -- QuickDraw
Availability: Macintosh.


module-Carbon.Qd.html | toolbox.html | module-Carbon.Qt.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.14 Carbon.Qdoffs -- QuickDraw Offscreen
Availability: Macintosh.


3.15 Carbon.Qt -- QuickTime

module-Carbon.Qdoffs.html | toolbox.html | module-Carbon.Res.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.15 Carbon.Qt -- QuickTime
Availability: Macintosh.


module-Carbon.Qt.html | toolbox.html | module-Carbon.Scrap.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.16 Carbon.Res -- Resource Manager and Handles
Availability: Macintosh.


3.17 Carbon.Scrap -- Scrap Manager

module-Carbon.Res.html | toolbox.html | module-Carbon.Snd.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.17 Carbon.Scrap -- Scrap Manager
Availability: Macintosh.
This module is only fully available on MacOS9 and earlier under classic PPC
MacPython. Very limited functionality is available under Carbon MacPython.
See Also:


3.18 Carbon.Snd -- Sound Manager

module-Carbon.Scrap.html | toolbox.html | module-Carbon.TE.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.18 Carbon.Snd -- Sound Manager
Availability: Macintosh.


3.19 Carbon.TE -- TextEdit

module-Carbon.Snd.html | toolbox.html | module-Carbon.Win.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.19 Carbon.TE -- TextEdit
Availability: Macintosh.


3.20 Carbon.Win -- Window Manager

module-Carbon.TE.html | toolbox.html | module-ColorPicker.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.20 Carbon.Win -- Window Manager
Availability: Macintosh.
---
module-Carbon.TE.html | toolbox.html | module-ColorPicker.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
Release 2.2, documentation updated on December 21, 2001.


module-pyresource.html | undocumented-modules.html | module-icopen.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.4 cfmfile -- Code Fragment Resource module
Availability: Macintosh.
cfmfile is a module that understands Code Fragments and the
accompanying ``cfrg'' resources. It can parse them and merge them, and is
used by BuildApplication to combine all plugin modules to a single
executable.


3.2 Cm -- Component Manager

module-AE.html | toolbox.html | module-Ctl.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.2 Cm -- Component Manager
Availability: Macintosh.


module-Carbon.Win.html | toolbox.html | undocumented-modules.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.21 ColorPicker --
Color selection dialog
Availability: Macintosh.
The ColorPicker module provides access to the standard color
picker dialog.


module-macpath.html | macpython-modules.html | connection-object.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.3 ctb --
Interface to the Communications Tool Box
Availability: Macintosh.
This module provides a partial interface to the Macintosh
Communications Toolbox. Currently, only Connection Manager tools are
supported.
This module is only available under MacOS9 or earlier, in classic PPC
MacPython.


3.3 Ctl -- Control Manager

module-Cm.html | toolbox.html | module-Dlg.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.3 Ctl -- Control Manager
Availability: Macintosh.


3.4 Dlg -- Dialog Manager

module-Ctl.html | toolbox.html | module-Evt.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.4 Dlg -- Dialog Manager
Availability: Macintosh.


speech-channel-objects.html | macpython-modules.html | module-FrameWork.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.10 EasyDialogs --
Basic Macintosh dialogs
Availability: Macintosh.
The EasyDialogs module contains some simple dialogs for
the Macintosh. All routines have an optional parameter id with
which you can override the DLOG resource used for the dialog, as long
as the item numbers correspond. See the source for details.
The EasyDialogs module defines the following functions:


3.5 Evt -- Event Manager

module-Dlg.html | toolbox.html | module-Fm.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.5 Evt -- Event Manager
Availability: Macintosh.


module-macostools.html | macpython-modules.html | module-macspeech.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.8 findertools --
The finder's Apple Events interface
Availability: Macintosh.
This module contains routines that give Python programs access to some
functionality provided by the finder. They are implemented as wrappers
around the AppleEventinterface to the finder.
All file and folder parameters can be specified either as full
pathnames or as FSSpec objects.
The findertools module defines the following functions:


3.6 Fm -- Font Manager

module-Evt.html | toolbox.html | module-List.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.6 Fm -- Font Manager
Availability: Macintosh.


module-EasyDialogs.html | macpython-modules.html | application-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.11 FrameWork --
Interactive application framework
Availability: Macintosh.
The FrameWork module contains classes that together provide a
framework for an interactive Macintosh application. The programmer
builds an application by creating subclasses that override various
methods of the bases classes, thereby implementing the functionality
wanted. Overriding functionality can often be done on various
different levels, i.e. to handle clicks in a single dialog window in a
non-standard way it is not necessary to override the complete event
handling.
The FrameWork is still very much work-in-progress, and the
documentation describes only the most important functionality, and not
in the most logical manner at that. Examine the source or the examples
for more details. The following are some comments posted on the
MacPython newsgroup about the strengths and limitations of
FrameWork:
> The strong point of FrameWork is that it allows you to break
> into the control-flow at many different places. W (module-W.html), for
> instance, uses a different way to enable/disable menus and that plugs
> right in leaving the rest intact. The weak points of
> FrameWork are that it has no abstract command interface (but
> that shouldn't be difficult), that it's dialog support is minimal and
> that it's control/toolbar support is non-existent.
The FrameWork module defines the following functions:


2.5 ic -- Access to Internet Config

finfo-objects.html | macpython-modules.html | node34.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.5 ic --
Access to Internet Config
Availability: Macintosh.
This module provides access to Macintosh Internet
Configpackage,
which stores preferences for Internet programs such as mail address,
default homepage, etc. Also, Internet Config contains an elaborate set
of mappings from Macintosh creator/type codes to foreign filename
extensions plus information on how to transfer files (binary, ascii,
etc.). Since MacOS 9, this module is a control panel named Internet.
There is a low-level companion module
icgluewhich provides the basic
Internet Config access functionality. This low-level module is not
documented, but the docstrings of the routines document the parameters
and the routine names are the same as for the Pascal or C API to
Internet Config, so the standard IC programmers' documentation can be
used if this module is needed.
The ic module defines the error exception and
symbolic names for all error codes Internet Config can produce; see
the source for details.
The ic module defines the following class and function:


module-cfmfile.html | undocumented-modules.html | module-macerrors.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.5 icopen -- Internet Config replacement for open()
Availability: Macintosh.
Importing icopen will replace the builtin open()
with a version that uses Internet Config to set file type and creator
for new files.


3.7 List -- List Manager

module-Fm.html | toolbox.html | module-Menu.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.7 List -- List Manager
Availability: Macintosh.


macpython-modules.html | macpython-modules.html | module-macpath.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.1 mac --
Implementations for the os module
Availability: Macintosh.
This module implements the operating system dependent functionality
provided by the standard module os. It is
best accessed through the os module.
The following functions are available in this module:
chdir(),
close(),
dup(),
fdopen(),
getcwd(),
lseek(),
listdir(),
mkdir(),
open(),
read(),
rename(),
rmdir(),
stat(),
sync(),
unlink(),
write(),
as well as the exception error. Note that the times
returned by stat() are floating-point values, like all time
values in MacPython.
One additional function is available:


connection-object.html | macpython-modules.html | dnr-result-object.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.4 macdnr --
Interface to the Macintosh Domain Name Resolver
Availability: Macintosh.
This module provides an interface to the Macintosh Domain Name
Resolver. It is usually used in conjunction with the mactcp (module-mactcp.html)
module, to map hostnames to IP addresses. It may not be available in
all Mac Python versions.
The macdnr module defines the following functions:


4.6 macerrors -- Mac OS Errors

module-icopen.html | undocumented-modules.html | module-macfsn.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.6 macerrors -- Mac OS Errors
Availability: Macintosh.
macerrors cotains constant definitions for many Mac OS error codes.


connection-object.html | macpython-modules.html | fsspec-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.4 macfs --
Various file system services
Availability: Macintosh.
This module provides access to Macintosh FSSpec handling, the Alias
Manager, finder aliases and the Standard File package.
Whenever a function or method expects a file argument, this
argument can be one of three things: (1) a full or partial Macintosh
pathname, (2) an FSSpec object or (3) a 3-tuple
`( wdRefNum , parID , name )` as described in
Inside Macintosh: Files. A description of aliases and the
Standard File package can also be found there.
Note:
A module, macfsn (module-macfsn.html), is auto-imported to replace
StandardFile calls in macfs with NavServices calls.


4.7 macfsn -- NavServices calls

module-macerrors.html | undocumented-modules.html | module-macresource.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.7 macfsn -- NavServices calls
Availability: Macintosh.
macfsn contains wrapper functions that have the same API as the macfs
StandardFile calls, but are implemented with Navigation Services through the
Nav (module-Nav.html)module. Importing it
will replace the methods in macfs (module-macfs.html)with these,
if Navigation Services is
available on your machine.


node34.html | macpython-modules.html | module-macostools.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.6 MacOS --
Access to Mac OS interpreter features
Availability: Macintosh.
This module provides access to MacOS specific functionality in the
Python interpreter, such as how the interpreter eventloop functions
and the like. Use with care.
Note the capitalization of the module name; this is a historical
artifact.


module-MacOS.html | macpython-modules.html | module-findertools.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.7 macostools --
Convenience routines for file manipulation
Availability: Macintosh.
This module contains some convenience routines for file-manipulation
on the Macintosh.
The macostools module defines the following functions:
Note that the process of creating finder aliases is not specified in
the Apple documentation. Hence, aliases created with mkalias()
could conceivably have incompatible behaviour in some cases.


module-mac.html | macpython-modules.html | module-ctb.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.2 macpath --
MacOS path manipulation functions
This module is the Macintosh implementation of the os.path
module. It is most portably accessed as
os.path. Refer to the
Python Library Reference (../lib/lib.html) for
documentation of os.path.


module-macfsn.html | undocumented-modules.html | module-Nac.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.8 macresource -- Locate script resources
Availability: Macintosh.
macresource helps scripts finding their resources, such as
dialogs and menus, without requiring special case code for when the
script is run under MacPython, as a MacPython applet or under OSX Python.


module-findertools.html | macpython-modules.html | voice-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.9 macspeech --
Interface to the Macintosh Speech Manager
Availability: Macintosh.
This module provides an interface to the Macintosh Speech Manager,
allowing you to let the Macintosh utter phrases. You need a version of
the Speech Manager extension (version 1 and 2 have been tested) in
your Extensions folder for this to work. The module does not
provide full access to all features of the Speech Manager.
This module is only available on MacOS9 and earlier in classic PPC
MacPython.


2.10 mactcp -- The MacTCP interfaces

module-findertools.html | macpython-modules.html | node41.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.10 mactcp --
The MacTCP interfaces
Availability: Macintosh.
This module provides an interface to the Macintosh TCP/IP driverMacTCP. There is an accompanying module,
macdnr (module-macdnr.html), which provides an interface
to the name-server (allowing you to translate hostnames to IP
addresses), a module MACTCPconstwhich has symbolic names for constants constants used by MacTCP. Since
the built-in module socketis also
available on the Macintosh it is usually easier to use sockets instead
of the Macintosh-specific MacTCP API.
A complete description of the MacTCP interface can be found in the
Apple MacTCP API documentation.


4.10 mactty -- Serial line connections

module-Nac.html | undocumented-modules.html | module-mkcwproject.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.10 mactty -- Serial line connections
Availability: Macintosh.
This module is only available under Mac OS 9 or earlier in classic PPC
MacPython.


3.8 Menu -- Menu Manager

module-List.html | toolbox.html | module-Qd.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.8 Menu -- Menu Manager
Availability: Macintosh.


dialogwindow-objects.html | macpython-modules.html | aeserver-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 2.12 MiniAEFrame --
Open Scripting Architecture server support
Availability: Macintosh.
The module MiniAEFrame provides a framework for an application
that can function as an Open Scripting Architecture
(OSA) server, i.e. receive and process
AppleEvents. It can be used in conjunction with
FrameWork (module-FrameWork.html)or standalone. As an
example, it is used in PythonCGISlave.
The MiniAEFrame module defines the following classes:


module-mactty.html | undocumented-modules.html | module-nsremote.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.11 mkcwproject -- Create CodeWarrior projects
Availability: Macintosh.
mkcwproject creates project files for the Metrowerks CodeWarrior
development environment. It is a helper module for
distutils (module-distutils.html)but can be used separately for more
control.


4.9 Nav -- NavServices calls

module-macresource.html | undocumented-modules.html | module-mactty.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.9 Nav -- NavServices calls
Availability: Macintosh.
A low-level interface to Navigation Services.


module-mkcwproject.html | undocumented-modules.html | module-PixMapWrapper.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.12 nsremote -- Wrapper around Netscape OSA modules
Availability: Macintosh.
nsremote is a wrapper around the Netscape OSA modules that
allows you to easily send your browser to a given URL. A related
module that may be of interest is the webbrowser module,
documented in the Python Library
Reference (../lib/lib.html).


module-nsremote.html | undocumented-modules.html | module-preferences.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.13 PixMapWrapper -- Wrapper for PixMap objects
Availability: Macintosh.
PixMapWrapper wraps a PixMap object with a Python object that
allows access to the fields by name. It also has methods to convert
to and from PIL images.


module-PixMapWrapper.html | undocumented-modules.html | module-pythonprefs.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.14 preferences -- Application preferences manager
Availability: Macintosh.
The preferences module allows storage of user preferences in
the system-wide preferences folder, with defaults coming from the
application itself and the possibility to override preferences for
specific situations.


module-buildtools.html | undocumented-modules.html | module-cfmfile.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.3 py_resource -- Resources from Python code
Availability: Macintosh.
This module is primarily used as a help module for
BuildApplet and BuildApplication. It is able to
store compiled Python code as 'PYC ' resources in a file.


module-preferences.html | undocumented-modules.html | module-quietconsole.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.15 pythonprefs -- Preferences manager for Python
Availability: Macintosh.
This module is a specialization of the preferences (module-preferences.html) module
that allows reading and writing of the preferences for the Python
interpreter.


3.9 Qd -- QuickDraw

module-Menu.html | toolbox.html | module-Qt.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.9 Qd -- QuickDraw
Availability: Macintosh.


3.10 Qt -- QuickTime

module-Qd.html | toolbox.html | module-Res.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.10 Qt -- QuickTime
Availability: Macintosh.


module-pythonprefs.html | undocumented-modules.html | module-videoreader.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.16 quietconsole -- non-visible stdout output
Availability: Macintosh.
quietconsole allows you to keep stdio output in a buffer
without displaying it (or without displaying the stdout window
altogether, if set with EditPythonPrefs) until you try to read from
stdin or disable the buffering, at which point all the saved output is
sent to the window. Good for programs with graphical user interfaces
that do want to display their output at a crash.


module-Qt.html | toolbox.html | module-Scrap.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.11 Res -- Resource Manager and Handles
Availability: Macintosh.


3.12 Scrap -- Scrap Manager

module-Res.html | toolbox.html | module-Snd.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.12 Scrap -- Scrap Manager
Availability: Macintosh.


3.13 Snd -- Sound Manager

module-Scrap.html | toolbox.html | module-TE.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.13 Snd -- Sound Manager
Availability: Macintosh.


3.14 TE -- TextEdit

module-Snd.html | toolbox.html | module-waste.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.14 TE -- TextEdit
Availability: Macintosh.


module-quietconsole.html | undocumented-modules.html | module-W.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.17 videoreader -- read QuickTime movies
Availability: Macintosh.
videoreader reads and decodes QuickTime movies and passes
a stream of images to your program. It also provides some support for
audio tracks.


4.18 W -- Widgets built on FrameWork

module-videoreader.html | undocumented-modules.html | module-waste.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.18 W -- Widgets built on FrameWork
Availability: Macintosh.
The W widgets are used extensively in the IDE.


module-W.html | undocumented-modules.html | node94.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4.19 waste -- non-Apple TextEdit replacement
Availability: Macintosh.
See Also:


3.16 Win -- Window Manager

module-waste.html | toolbox.html | module-ColorPicker.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3.16 Win -- Window Manager
Availability: Macintosh.
---
module-waste.html | toolbox.html | module-ColorPicker.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
Release 2.1, documentation updated on April 15, 2001.


1.5 Creating a Python script

argv.html | using.html | node11.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.5 Creating a Python script
Since Python scripts are simply text files, they can be created in any
way that text files can be created, but some special tools also exist
with extra features.


1.5.1 In an editor

node10.html | node10.html | node12.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.5.1 In an editor
You can create a text file with any word processing program such as
MSWord or AppleWorks but you need to make sure
that the file is saved as ``ASCII'' or ``plain text''.


1.5.1.1 Editors with Python modes

node11.html | node11.html | scripting-with-BBedit.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
### 1.5.1.1 Editors with Python modes
Several text editors have additional features that add functionality
when you are creating a Python script. These can include coloring
Python keywords to make your code easier to read, module browsing, or
a built-in debugger. These include Alpha, Pepper,
and BBedit, and the MacPython IDE (Section 1.6 (IDE.html#IDE)).


IDE.html | IDE.html | IDEwrite.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.6.1 Using the ``Python Interactive'' window
Use this window like you would the PythonInterpreter, except
that you cannot use the ``Drag and drop'' method above. Instead,
dropping a script onto the Python IDE icon will open the
file in a separate script window (which you can then execute manually
- see section 1.6.3 (IDEexecution.html#IDEexecution)).


1.8 Mac OS X

defaults.html | using.html | macpython-modules.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.8 Mac OS X
At the time of this writing Mac OS X had just been released as a
Public Beta. Efforts are under way to bring MacPython to Mac OS X. The
MacPython release 2.21.5.2c1 runs quite well within the
``Classic'' environment. A ``Carbon'' port of the MacPython code is
being prepared for release, and several people have made a command
line version available to the ``Darwin'' layer (which is accessible
via Terminal.app).


2.5.1 IC Objects

module-ic.html | module-ic.html | module-MacOS.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.5.1 IC Objects
IC objects have a mapping interface, hence to obtain the mail
address you simply get `ic ['MailAddress']`. Assignment also
works, and changes the option in the configuration file.
The module knows about various datatypes, and converts the internal IC
representation to a ``logical'' Python data structure. Running the
ic module standalone will run a test program that lists all
keys and values in your IC database, this will have to serve as
documentation.
If the module does not know how to represent the data it returns an
instance of the `ICOpaqueData` type, with the raw data in its
data attribute. Objects of this type are also acceptable values
for assignment.
Besides the dictionary interface, IC objects have the
following methods:


2.6.1 IC Objects

module-ic.html | module-ic.html | module-MacOS.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.6.1 IC Objects
IC objects have a mapping interface, hence to obtain the mail
address you simply get `ic ['MailAddress']`. Assignment also
works, and changes the option in the configuration file.
The module knows about various datatypes, and converts the internal IC
representation to a ``logical'' Python data structure. Running the
ic module standalone will run a test program that lists all
keys and values in your IC database, this will have to serve as
documentation.
If the module does not know how to represent the data it returns an
instance of the `ICOpaqueData` type, with the raw data in its
data attribute. Objects of this type are also acceptable values
for assignment.
Besides the dictionary interface, IC objects have the
following methods:


2.10.1 TCP Stream Objects

module-mactcp.html | module-mactcp.html | node42.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.10.1 TCP Stream Objects


2.10.2 TCP Status Objects

node41.html | module-mactcp.html | node43.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.10.2 TCP Status Objects
This object has no methods, only some members holding information on
the connection. A complete description of all fields in this objects
can be found in the Apple documentation. The most interesting ones are:


2.10.3 UDP Stream Objects

node42.html | module-mactcp.html | module-macspeech.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.10.3 UDP Stream Objects
Note that, unlike the name suggests, there is nothing stream-like
about UDP.


1.3 How to run a Python script

interpreter.html | using.html | node7.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1.3 How to run a Python script
There are several ways to run an existing Python script; two common
ways to run a Python script are ``drag and drop'' and ``double
clicking''. Other ways include running it from within the IDE (see
Section 1.6 (IDE.html#IDE)), or launching via AppleScript.


1.3.1 Drag and drop

node6.html | node6.html | creator-code.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.3.1 Drag and drop
One of the easiest ways to launch a Python script is via ``Drag and
Drop''. This is just like launching a text file in the Finder by
``dragging'' it over your word processor's icon and ``dropping'' it
there. Make sure that you use an icon referring to the
PythonInterpreter, not the IDE or Idle
icons which have different behaviour which is described below.
Some things that might have gone wrong:
- A window flashes after dropping the script onto the
PythonInterpreter, but then disappears. Most likely this is a
configuration issue; your PythonInterpreter is setup to exit
immediately upon completion, but your script assumes that if it prints
something that text will stick around for a while. To fix this, see
section 1.7.3 (defaults.html#defaults).
- After dropping the script onto the PythonInterpreter, a
window appeared which said: ``File contains `\r` characters
(incorrect line endings?)''. That script probably originated on a
Unix or Windows machine. You will need to change the line endings
to the standard Mac usage. One way to do this is to open the file in
BBedit
(http://www.barebones.com/products/bbedit_lite.html) which can
easily change the line endings between Mac, DOS, and Unix styles.
- When you waved the script icon over the PythonInterpreter,
the PythonInterpreter icon did not hilight. Most likely the
Creator code and document type is unset (or set incorrectly) - this
often happens when a file originates on a non-Mac computer. See
section 1.3.2 (creator-code.html#creator-code) for more details.


A. History and License

module-waste.html | mac.html | node95.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# A. History and License


A.1 History of the software

node94.html | node94.html | node96.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# A.1 History of the software
Python was created in the early 1990s by Guido van Rossum at Stichting
Mathematisch Centrum (CWI, see http://www.cwi.nl/) in the Netherlands
as a successor of a language called ABC. Guido remains Python's
principal author, although it includes many contributions from others.
In 1995, Guido continued his work on Python at the Corporation for
National Research Initiatives (CNRI, see http://www.cnri.reston.va.us/)
in Reston, Virginia where he released several versions of the
software.
In May 2000, Guido and the Python core development team moved to
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
year, the PythonLabs team moved to Zope Corporation (then Digital
Creations; see http://www.zope.com/). In 2001, the Python
Software Foundation (PSF, see http://www.python.org/psf/) was
formed, a non-profit organization created specifically to own
Python-related Intellectual Property. Digital Creations is a
sponsoring member of the PSF.
All Python releases are Open Source (see
http://www.opensource.org/ for the Open Source Definition).
Historically, most, but not all, Python releases have also been
GPL-compatible; the table below summarizes the various releases.
Note:
GPL-compatible doesn't mean that we're distributing
Python under the GPL. All Python licenses, unlike the GPL, let you
distribute a modified version without making your changes open source.
The GPL-compatible licenses make it possible to combine Python with
other software that is released under the GPL; the others don't.
Thanks to the many outside volunteers who have worked under Guido's
direction to make these releases possible.


node95.html | node94.html | modindex.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# A.2 Terms and conditions for accessing or otherwise using Python
PSF LICENSE AGREEMENT FOR PYTHON 2.2
1. This LICENSE AGREEMENT is between the Python Software Foundation
(``PSF''), and the Individual or Organization (``Licensee'') accessing
and otherwise using Python 2.2 software in source or binary
form and its associated documentation.
2. Subject to the terms and conditions of this License Agreement, PSF
hereby grants Licensee a nonexclusive, royalty-free, world-wide
license to reproduce, analyze, test, perform and/or display publicly,
prepare derivative works, distribute, and otherwise use Python
2.2 alone or in any derivative version, provided, however, that
PSF's License Agreement and PSF's notice of copyright, i.e.,
``Copyright © 2001 Python Software Foundation; All Rights
Reserved'' are retained in Python 2.2 alone or in any
derivative version prepared by Licensee.
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python 2.2 or any part thereof, and wants to
make the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python 2.2.
4. PSF is making Python 2.2 available to Licensee on an ``AS IS''
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 2.2 WILL
NOT INFRINGE ANY THIRD PARTY RIGHTS.
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
2.2 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON
2.2, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE
POSSIBILITY THEREOF.
6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between PSF and
Licensee. This License Agreement does not grant permission to use PSF
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.
8. By copying, installing or otherwise using Python 2.2, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.
BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
1. This LICENSE AGREEMENT is between BeOpen.com (``BeOpen''), having an
office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
Individual or Organization (``Licensee'') accessing and otherwise
using this software in source or binary form and its associated
documentation (``the Software'').
2. Subject to the terms and conditions of this BeOpen Python License
Agreement, BeOpen hereby grants Licensee a non-exclusive,
royalty-free, world-wide license to reproduce, analyze, test, perform
and/or display publicly, prepare derivative works, distribute, and
otherwise use the Software alone or in any derivative version,
provided, however, that the BeOpen Python License is retained in the
Software, alone or in any derivative version prepared by Licensee.
3. BeOpen is making the Software available to Licensee on an ``AS IS''
basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
5. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
6. This License Agreement shall be governed by and interpreted in all
respects by the law of the State of California, excluding conflict of
law provisions. Nothing in this License Agreement shall be deemed to
create any relationship of agency, partnership, or joint venture
between BeOpen and Licensee. This License Agreement does not grant
permission to use BeOpen trademarks or trade names in a trademark
sense to endorse or promote products or services of Licensee, or any
third party. As an exception, the ``BeOpen Python'' logos available
at http://www.pythonlabs.com/logos.html may be used according to the
permissions granted on that web page.
7. By copying, installing or otherwise using the software, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.
CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
1. This LICENSE AGREEMENT is between the Corporation for National
Research Initiatives, having an office at 1895 Preston White Drive,
Reston, VA 20191 (``CNRI''), and the Individual or Organization
(``Licensee'') accessing and otherwise using Python 1.6.1 software in
source or binary form and its associated documentation.
2. Subject to the terms and conditions of this License Agreement, CNRI
hereby grants Licensee a nonexclusive, royalty-free, world-wide
license to reproduce, analyze, test, perform and/or display publicly,
prepare derivative works, distribute, and otherwise use Python 1.6.1
alone or in any derivative version, provided, however, that CNRI's
License Agreement and CNRI's notice of copyright, i.e., ``Copyright
© 1995-2001 Corporation for National Research Initiatives;
All Rights Reserved'' are retained in Python 1.6.1 alone or in any
derivative version prepared by Licensee. Alternately, in lieu of
CNRI's License Agreement, Licensee may substitute the following text
(omitting the quotes): ``Python 1.6.1 is made available subject to the
terms and conditions in CNRI's License Agreement. This Agreement
together with Python 1.6.1 may be located on the Internet using the
following unique, persistent identifier (known as a handle):
1895.22/1013. This Agreement may also be obtained from a proxy server
on the Internet using the following URL:
http://hdl.handle.net/1895.22/1013.''
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python 1.6.1 or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python 1.6.1.
4. CNRI is making Python 1.6.1 available to Licensee on an ``AS IS''
basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
7. This License Agreement shall be governed by the federal
intellectual property law of the United States, including without
limitation the federal copyright law, and, to the extent such
U.S. federal law does not apply, by the law of the Commonwealth of
Virginia, excluding Virginia's conflict of law provisions.
Notwithstanding the foregoing, with regard to derivative works based
on Python 1.6.1 that incorporate non-separable material that was
previously distributed under the GNU General Public License (GPL), the
law of the Commonwealth of Virginia shall govern this License
Agreement only as to issues arising under or with respect to
Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
License Agreement shall be deemed to create any relationship of
agency, partnership, or joint venture between CNRI and Licensee. This
License Agreement does not grant permission to use CNRI trademarks or
trade name in a trademark sense to endorse or promote products or
services of Licensee, or any third party.
8. By clicking on the ``ACCEPT'' button where indicated, or by copying,
installing or otherwise using Python 1.6.1, Licensee agrees to be
bound by the terms and conditions of this License Agreement.
ACCEPT
CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
Copyright © 1991 - 1995, Stichting Mathematisch Centrum
Amsterdam, The Netherlands. All rights reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


1.5.1.2 BBedit

node12.html | node11.html | IDE.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
### 1.5.1.2 BBedit
If you use BBEdit to create your scripts you will want to tell it about the Python creator code so that
you can simply double click on the saved file to launch it.
- Launch BBEdit.
- Select ``Preferences'' from the ``Edit'' menu.
- Select ``File Types'' from the scrolling list.
- click on the ``Add...'' button and navigate to
PythonInterpreter in the main directory of the
MacPython distribution; click ``open''.
- Click on the ``Save'' button in the Preferences panel.


2.11.4 ScrolledWindow Object

controlswindow-object.html | module-FrameWork.html | dialogwindow-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.11.4 ScrolledWindow Object
ScrolledWindow objects are ControlsWindow objects with the following
extra methods:


EditPythonPrefs.html | configuration.html | defaults.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 1.7.2 Adding modules to the Module Search Path
When executing an import statement, Python looks for modules
in places defined by the sys.path To edit the
sys.path on a Mac, launch EditPythonPrefs, and
enter them into the largish field at the top (one per line).
Since MacPython defines a main Python directory, the easiest thing is
to add folders to search within the main Python directory. To add a
folder of scripts that you created called ``My Folder'' located in the
main Python Folder, enter "$(PYTHON):My Folder" onto a new line.
To add the Desktop under OS 9 or below, add
"StartupDriveName:Desktop Folder" on a new line.


2.9.2 Speech Channel Objects

voice-objects.html | module-macspeech.html | module-EasyDialogs.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.9.2 Speech Channel Objects
A Speech Channel object allows you to speak strings with slightly more
control than SpeakString(), and allows you to use multiple
speakers at the same time. Please note that channel pitch and rate are
interrelated in some way, so that to make your Macintosh sing you will
have to adjust both.


3. MacOS Toolbox Modules

module-aetypes.html | mac.html | module-Carbon.AE.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 3. MacOS Toolbox Modules
There are a set of modules that provide interfaces to various MacOS
toolboxes. If applicable the module will define a number of Python
objects for the various structures declared by the toolbox, and
operations will be implemented as methods of the object. Other
operations will be implemented as functions in the module. Not all
operations possible in C will also be possible in Python (callbacks
are often a problem), and parameters will occasionally be different in
Python (input and output buffers, especially). All methods and
functions have a __doc__ string describing their arguments
and return values, and for additional description you are referred to
Inside
Macintosh (http://developer.apple.com/techpubs/macos8/mac8.html) or similar works.
These modules all live in a package called Carbon. Despite the
name Carbon they are also available under classic PPC MacPython.
The normal use pattern is
```text

from Carbon import AE
```
Warning! These modules are not yet documented. If you
wish to contribute documentation of any of these modules, please get
in touch with python-docs@python.org.
Carbon.AE (module-Carbon.AE.html) | Interface to the Apple Events toolbox
Carbon.App (module-Carbon.App.html) | Interface to the Appearance Manager
Carbon.CF (module-Carbon.CF.html) | Interface to the Core Foundation
Carbon.Cm (module-Carbon.Cm.html) | Interface to the Component Manager
Carbon.Ctl (module-Carbon.Ctl.html) | Interface to the Control Manager
Carbon.Dlg (module-Carbon.Dlg.html) | Interface to the Dialog Manager
Carbon.Evt (module-Carbon.Evt.html) | Interface to the Event Manager
Carbon.Fm (module-Carbon.Fm.html) | Interface to the Font Manager
Carbon.Help (module-Carbon.Help.html) | Interface to the Balloon Help Manager
Carbon.List (module-Carbon.List.html) | Interface to the List Manager
Carbon.Menu (module-Carbon.Menu.html) | Interface to the Menu Manager
Carbon.Mlte (module-Carbon.Mlte.html) | Interface to the MultiLingual Text Editor
Carbon.Qd (module-Carbon.Qd.html) | Interface to the QuickDraw toolbox
Carbon.Qdoffs (module-Carbon.Qdoffs.html) | Interface to the QuickDraw Offscreen APIs
Carbon.Qt (module-Carbon.Qt.html) | Interface to the QuickTime toolbox
Carbon.Res (module-Carbon.Res.html) | Interface to the Resource Manager and Handles
Carbon.Scrap (module-Carbon.Scrap.html) | The Scrap Manager provides basic services for
implementing cut & paste and clipboard operations.
Carbon.Snd (module-Carbon.Snd.html) | Interface to the Sound Manager
Carbon.TE (module-Carbon.TE.html) | Interface to TextEdit
Carbon.Win (module-Carbon.Win.html) | Interface to the Window Manager
ColorPicker (module-ColorPicker.html) | Interface to the standard color selection dialog.


4. Undocumented Modules

module-ColorPicker.html | mac.html | module-applesingle.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 4. Undocumented Modules
The modules in this chapter are poorly documented (if at all). If you
wish to contribute documentation of any of these modules, please get in
touch with
python-docs@python.org (mailto:python-docs@python.org).
applesingle (module-applesingle.html) | Rudimentary decoder for AppleSingle format files
buildtools (module-buildtools.html) | Helper module for BuildApplet, BuildApplication and
macfreeze
py_resource (module-pyresource.html) | Helper to create 'PYC ' resources for compiled
applications
cfmfile (module-cfmfile.html) | Code Fragment Resource module
icopen (module-icopen.html) | Internet Config replacement for open()
macerrors (module-macerrors.html) | Constant definitions for many Mac OS error codes
macfsn (module-macfsn.html) | NavServices versions of StandardFile calls
macresource (module-macresource.html) | Locate script resources
Nac (module-Nac.html) | Interface to Navigation Services
mactty (module-mactty.html) | Easy access serial to line connections
mkcwproject (module-mkcwproject.html) | Create CodeWarrior projects
nsremote (module-nsremote.html) | Wrapper around Netscape OSA modules
PixMapWrapper (module-PixMapWrapper.html) | Wrapper for PixMap objects
preferences (module-preferences.html) | Nice application preferences manager with support for
defaults
pythonprefs (module-pythonprefs.html) | Specialized preferences manager for the Python
interpreter
quietconsole (module-quietconsole.html) | buffered, non-visible stdout output
videoreader (module-videoreader.html) | read QuickTime movies frame by frame for further processing
W (module-W.html) | Widgets for the Mac, built on top of FrameWork
waste (module-waste.html) | Interface to the ``WorldScript-Aware Styled Text Engine.''


1. Using Python on the Macintosh

contents.html | mac.html | getting.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
# 1. Using Python on the Macintosh
Using Python on the Macintosh can seem like something completely
different than using it on a Unix-like or Windows system. Most of the
Python documentation, both the ``official'' documentation and
published books, describe only how Python is used on these systems,
causing confusion for the new user of MacPython. This chapter gives a
brief introduction to the specifics of using Python on a Macintosh.


2.9.1 Voice Objects

module-macspeech.html | module-macspeech.html | speech-channel-objects.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.9.1 Voice Objects
Voice objects contain the description of a voice. It is currently not
yet possible to access the parameters of a voice.


2.11.2 Window Objects

application-objects.html | module-FrameWork.html | controlswindow-object.html | Macintosh Library Modules | contents.html | modindex.html | genindex.html
---
## 2.11.2 Window Objects
Window objects have the following methods, among others:


Global Module Index

./ | Global Module Index
---
## Global Module Index
Some module names are followed by an annotation indicating what
platform they are available on.