blob: 8e364270fccebf96cf9331224497a624937c034b [file] [log] [blame]
Guido van Rossum515834a1991-01-22 11:45:29 +00001% Format this file with latex.
2
Guido van Rossum8ec63501991-02-19 12:53:17 +00003%\documentstyle[garamond,11pt,myformat]{article}
Guido van Rossumd38b7641991-01-25 13:26:13 +00004\documentstyle[11pt,myformat]{article}
Guido van Rossum515834a1991-01-22 11:45:29 +00005
Guido van Rossumd38b7641991-01-25 13:26:13 +00006% A command to force the text after an item to start on a new line
7\newcommand{\itembreak}{
8 \mbox{}\\*[0mm]
9}
Guido van Rossum515834a1991-01-22 11:45:29 +000010
Guido van Rossum8ec63501991-02-19 12:53:17 +000011% A command to define a function item
12\newcommand{\funcitem}[2]{\item[#1(#2)]}
13
14% A command to define an exception item
15\newcommand{\excitem}[2]{
16\item[#1 = {\tt '#2'}]
17\itembreak
18}
19
Guido van Rossum515834a1991-01-22 11:45:29 +000020\title{\bf
21 Python Library Reference \\
22 (DRAFT)
23}
24
25\author{
26 Guido van Rossum \\
27 Dept. CST, CWI, Kruislaan 413 \\
28 1098 SJ Amsterdam, The Netherlands \\
29 E-mail: {\tt guido@cwi.nl}
30}
31
32\begin{document}
33
34\pagenumbering{roman}
35
36\maketitle
37
38\begin{abstract}
39
40\noindent
41This document describes the built-in types, exceptions and functions and
42the standard modules that come with the {\Python} system.
43It assumes basic knowledge about the {\Python} language.
44For an informal introduction to the language, see the Tutorial document.
45The Language Reference document (XXX not yet existing)
46gives a more formal reference to the language.
47
48\end{abstract}
49
50\pagebreak
51
52\tableofcontents
53
54\pagebreak
55
56\pagenumbering{arabic}
57
58\section{Introduction}
59
60The {\Python} library consists of three parts, with different levels of
61integration with the interpreter.
62Closest to the interpreter are built-in types, exceptions and functions.
63Next are built-in modules, which are written in C and linked statically
64with the interpreter.
65Finally there are standard modules that are implemented entirely in
66{\Python}, but are always available.
67For efficiency, some standard modules may become built-in modules in
68future versions of the interpreter.
69
70\section{Built-in Types, Exceptions and Functions}
71
72Names for built-in exceptions and functions are found in a separate
73read-only symbol table which cannot be modified.
74This table is searched last, so local and global user-defined names can
75override built-in names.
76Built-in types have no names but are created by syntactic constructs
77(such as constants) or built-in functions.
78They are described together here for easy reference.%
79\footnote{
80The descriptions sorely lack explanations of the exceptions that
81may be raised---this will be fixed in a future version of this
82document.
83}
84
85\subsection{Built-in Types}
86
87The following sections describe the standard types that are built into the
88interpreter.
89\subsubsection{Numeric Types}
90
91There are two numeric types: integers and floating point numbers.
92Integers are implemented using {\tt long} in C, so they have at least 32
93bits of precision.
94Floating point numbers are implemented using {\tt double} in C.
95All bets on precision are off.
96Numbers are created by numeric constants or as the result of built-in
97functions and operators.
98
99Numeric types support the following operations:
100
101\begin{center}
102\begin{tabular}{|c|l|c|}
103\hline
104Operation & Result & Notes \\
105\hline
106{\tt abs}({\em x}) & absolute value of {\em x} & \\
107{\tt int}({\em x}) & {\em x} converted to integer & (1) \\
108{\tt float}({\em x}) & {\em x} converted to floating point & \\
109{\tt -}{\em x} & {\em x} negated & \\
110{\tt +}{\em x} & {\em x} unchanged & \\
111{\em x}{\tt +}{\em y} & sum of {\em x} and {\em y} & \\
112{\em x}{\tt -}{\em y} & difference of {\em x} and {\em y} & \\
113{\em x}{\tt *}{\em y} & product of {\em x} and {\em y} & \\
114{\em x}{\tt /}{\em y} & quotient of {\em x} and {\em y} & (2) \\
115{\em x}{\tt \%}{\em y} & remainder of {\em x}{\tt /}{\em y} & (3) \\
116\hline
117\end{tabular}
118\end{center}
119
120\noindent
121Notes:
122\begin{description}
123\item[(1)]
124This may round or truncate as in C; see functions {\tt floor} and
125{\tt ceil} in module {\tt math}.
126\item[(2)]
127Integer division is defined as in C: the result is an integer; with
128positive operands, it truncates towards zero; with a negative operand,
129the result is unspecified.
130\item[(3)]
131Only defined for integers.
132\end{description}
133
134Mixed arithmetic is not supported; both operands must have the same type.
135Mixed comparisons return the wrong result (floats always compare smaller
136than integers).%
137\footnote{
138These restrictions are bugs in the language definitions and will be
139fixed in the future.
140}
141\subsubsection{Sequence Types}
142
143There are three sequence types: strings, lists and tuples.
144Strings constants are written in single quotes: {\tt 'xyzzy'}.
145Lists are constructed with square brackets: {\tt [a,~b,~c]}.
146Tuples are constructed by the comma operator or with an empty set of
147parentheses: {\tt a,~b,~c} or {\tt ()}.
148
149Sequence types support the following operations ({\em s} and {\em t} are
150sequences of the same type; {\em n}, {\em i} and {\em j} are integers):
151
152\begin{center}
153\begin{tabular}{|c|l|c|}
154\hline
155Operation & Result & Notes \\
156\hline
157{\tt len}({\em s}) & length of {\em s} & \\
158{\tt min}({\em s}) & smallest item of {\em s} & \\
159{\tt max}({\em s}) & largest item of {\em s} & \\
160{\em x} {\tt in} {\em s} &
161 true if an item of {\em s} is equal to {\em x} & \\
162{\em x} {\tt not} {\tt in} {\em s} &
163 false if an item of {\em s} is equal to {\em x} & \\
164{\em s}{\tt +}{\em t} & the concatenation of {\em s} and {\em t} & \\
165{\em s}{\tt *}{\em n}, {\em n}*{\em s} &
166 {\em n} copies of {\em s} concatenated & (1) \\
167{\em s}[{\em i}] & {\em i}'th item of {\em s} & \\
168{\em s}[{\em i}:{\em j}] &
169 slice of {\em s} from {\em i} to {\em j} & (2) \\
170\hline
171\end{tabular}
172\end{center}
173
174\noindent
175Notes:
176\begin{description}
177\item[(1)]
178Sequence repetition is only supported for strings.
179\item[(2)]
180The slice of $s$ from $i$ to $j$ is defined as the sequence
181of items with index $k$ such that $i \leq k < j$.
182Special rules apply for negative and omitted indices; see the Tutorial
183or the Reference Manual.
184\end{description}
185
186\paragraph{Mutable Sequence Types.}
187
188List objects support additional operations that allow in-place
189modification of the object.
190These operations would be supported by other mutable sequence types
191(when added to the language) as well.
192Strings and tuples are immutable sequence types and such objects cannot
193be modified once created.
194The following operations are defined on mutable sequence types (where
195{\em x} is an arbitrary object):
196
197\begin{center}
198\begin{tabular}{|c|l|}
199\hline
200Operation & Result \\
201\hline
202{\em s}[{\em i}] = {\em x} &
203 item {\em i} of {\em s} is replaced by {\em x} \\
204{\em s}[{\em i}:{\em j}] = {\em t} &
205 slice of {\em s} from {\em i} to {\em j} is replaced by {\em t} \\
206{\tt del} {\em s}[{\em i}:{\em j}] &
207 same as {\em s}[{\em i}:{\em j}] = [] \\
208{\em s}.{\tt append}({\em x}) &
209 same as {\em s}[{\tt len}({\em x}):{\tt len}({\em x})] = [{\em x}] \\
210{\em s}.{\tt insert}({\em i}, {\em x}) &
211 same as {\em s}[{\em i}:{\em i}] = [{\em x}] \\
212{\em s}.{\tt sort}() &
213 the items of {\em s} are permuted to satisfy \\
214 &
215 $s[i] \leq s[j]$ for $i < j$\\
216\hline
217\end{tabular}
218\end{center}
219
220\subsubsection{Mapping Types}
221
222A
223{\em mapping}
224object maps values of one type (the key type) to arbitrary objects.
225Mappings are mutable objects.
226There is currently only one mapping type, the
227{\em dictionary}.
228A dictionary's keys are strings.
229An empty dictionary is created by the expression \verb"{}".
230An extension of this notation is used to display dictionaries when
231written (see the example below).
232
233The following operations are defined on mappings (where {\em a} is a
234mapping, {\em k} is a key and {\em x} is an arbitrary object):
235
236\begin{center}
237\begin{tabular}{|c|l|c|}
238\hline
239Operation & Result & Notes\\
240\hline
241{\tt len}({\em a}) & the number of elements in {\em a} & \\
242{\em a}[{\em k}] & the item of {\em a} with key {\em k} & \\
243{\em a}[{\em k}] = {\em x} & set {\em a}[{\em k}] to {\em x} & \\
244{\tt del} {\em a}[{\em k}] & remove {\em a}[{\em k}] from {\em a} & \\
245{\em a}.{\tt keys}() & a copy of {\em a}'s list of keys & (1) \\
246{\em a}.{\tt has\_key}({\em k}) & true if {\em a} has a key {\em k} & \\
247\hline
248\end{tabular}
249\end{center}
250
251\noindent
252Notes:
253\begin{description}
254\item[(1)]
255Keys are listed in random order.
256\end{description}
257
258A small example using a dictionary:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000259\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000260>>> tel = {}
261>>> tel['jack'] = 4098
262>>> tel['sape'] = 4139
263>>> tel['guido'] = 4127
264>>> tel['jack']
2654098
266>>> tel
267{'sape': 4139; 'guido': 4127; 'jack': 4098}
268>>> del tel['sape']
269>>> tel['irv'] = 4127
270>>> tel
271{'guido': 4127; 'irv': 4127; 'jack': 4098}
272>>> tel.keys()
273['guido', 'irv', 'jack']
274>>> tel.has_key('guido')
2751
276>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +0000277\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +0000278\subsubsection{Other Built-in Types}
279
280The interpreter supports several other kinds of objects.
281Most of these support only one or two operations.
282
283\paragraph{Modules.}
284
285The only operation on a module is member acces: {\em m}{\tt .}{\em name},
286where {\em m} is a module and {\em name} accesses a name defined in
287{\em m}'s symbol table.
288Module members can be assigned to.
289
290\paragraph{Classes and Class Objects.}
291
292XXX Classes will be explained at length in a later version of this
293document.
294
295\paragraph{Functions.}
296
297Function objects are created by function definitions.
298The only operation on a function object is to call it:
299{\em func}({\em optional-arguments}).
300
301Built-in functions have a different type than user-defined functions,
302but they support the same operation.
303
304\paragraph{Methods.}
305
306Methods are functions that are called using the member acces notation.
307There are two flavors: built-in methods (such as {\tt append()} on
308lists) and class member methods.
309Built-in methods are described with the types that support them.
310XXX Class member methods will be described in a later version of this
311document.
312
313\paragraph{Type Objects.}
314
315Type objects represent the various object types.
316An object's type is accessed by the built-in function
317{\tt type()}.
318There are no operations on type objects.
319
320\paragraph{The Null Object.}
321
322This object is returned by functions that don't explicitly return a
323value.
324It supports no operations.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000325There is exactly one null object, named {\tt None}
326(a built-in name).
Guido van Rossum515834a1991-01-22 11:45:29 +0000327
328\paragraph{File Objects.}
329
330File objects are implemented using C's
331{\em stdio}
332package and can be created with the built-in function
333{\tt open()}.
334They have the following methods:
335\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000336\funcitem{close}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000337Closes the file.
338A closed file cannot be read or written anymore.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000339\funcitem{read}{size}
Guido van Rossum515834a1991-01-22 11:45:29 +0000340Reads at most
341{\tt size}
342bytes from the file (less if the read hits EOF).
343The bytes are returned as a string object.
344An empty string is returned when EOF is hit immediately.
345(For certain files, like ttys, it makes sense to continue reading after
346an EOF is hit.)
Guido van Rossum8ec63501991-02-19 12:53:17 +0000347\funcitem{readline}{size}
Guido van Rossum515834a1991-01-22 11:45:29 +0000348Reads a line of at most
349{\tt size}
350bytes from the file.
351A trailing newline character, if present, is kept in the string.
352The size is optional and defaults to a large number (but not infinity).
353EOF is reported as by
354{\tt read().}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000355\funcitem{write}{str}
Guido van Rossum515834a1991-01-22 11:45:29 +0000356Writes a string to the file.
357Returns no value.
358\end{description}
359
360\subsection{Built-in Exceptions}
361
362The following exceptions can be generated by the interpreter or
363built-in functions.
364Except where mentioned, they have a string argument (also known as the
365`associated value' of an exception) indicating the detailed cause of the
366error.
367The strings listed with the exception names are their values when used
368in an expression or printed.
369\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000370\excitem{EOFError}{end-of-file read}
371(No argument.)
Guido van Rossum515834a1991-01-22 11:45:29 +0000372Raised when a built-in function ({\tt input()} or {\tt raw\_input()})
373hits an end-of-file condition (EOF) without reading any data.
374(N.B.: the {\tt read()} and {\tt readline()} methods of file objects
375return an empty string when they hit EOF.)
Guido van Rossum8ec63501991-02-19 12:53:17 +0000376\excitem{KeyboardInterrupt}{end-of-file read}
377(No argument.)
Guido van Rossum515834a1991-01-22 11:45:29 +0000378Raised when the user hits the interrupt key (normally Control-C or DEL).
379During execution, a check for interrupts is made regularly.
380Interrupts typed when a built-in function ({\tt input()} or
381{\tt raw\_input()}) is waiting for input also raise this exception.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000382\excitem{MemoryError}{out of memory}
Guido van Rossum515834a1991-01-22 11:45:29 +0000383%.br
384Raised when an operation runs out of memory but the situation
385may still be rescued (by deleting some objects).
Guido van Rossum8ec63501991-02-19 12:53:17 +0000386\excitem{NameError}{undefined name}
Guido van Rossum515834a1991-01-22 11:45:29 +0000387%.br
388Raised when a name is not found.
389This applies to unqualified names, module names (on {\tt import}),
390module members and object methods.
391The string argument is the name that could not be found.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000392\excitem{RuntimeError}{run-time error}
Guido van Rossum515834a1991-01-22 11:45:29 +0000393%.br
394Raised for a variety of reasons, e.g., division by zero or index out of
395range.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000396\excitem{SystemError}{system error}
Guido van Rossum515834a1991-01-22 11:45:29 +0000397%.br
398Raised when the interpreter finds an internal error, but the situation
399does not look so serious to cause it to abandon all hope.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000400\excitem{TypeError}{type error}
Guido van Rossum515834a1991-01-22 11:45:29 +0000401%.br
402Raised when an operation or built-in function is applied to an object of
403inappropriate type.
404\end{description}
405
406\subsection{Built-in Functions}
407
408The {\Python} interpreter has a small number of functions built into it that
409are always available.
410They are listed here in alphabetical order.
411\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000412\funcitem{abs}{x}
Guido van Rossum515834a1991-01-22 11:45:29 +0000413Returns the absolute value of a number.
414The argument may be an integer or floating point number.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000415\funcitem{chr}{i}
416Returns a string of one character
417whose ASCII code is the integer {\tt i},
418e.g., {\tt chr(97)} returns the string {\tt 'a'}.
419This is the inverse of {\tt ord()}.
420\funcitem{dir}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000421Without arguments, this function returns the list of names in the
422current local symbol table, sorted alphabetically.
423With a module object as argument, it returns the sorted list of names in
424that module's global symbol table.
425For example:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000426\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000427>>> import sys
428>>> dir()
429['sys']
430>>> dir(sys)
431['argv', 'exit', 'modules', 'path', 'stderr', 'stdin', 'stdout']
432>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +0000433\end{verbatim}\ecode
Guido van Rossum8ec63501991-02-19 12:53:17 +0000434\funcitem{divmod}{a, b}
Guido van Rossum515834a1991-01-22 11:45:29 +0000435%.br
436Takes two integers as arguments and returns a pair of integers
437consisting of their quotient and remainder.
438For
Guido van Rossumd38b7641991-01-25 13:26:13 +0000439\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000440q, r = divmod(a, b)
Guido van Rossumd38b7641991-01-25 13:26:13 +0000441\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +0000442the invariants are:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000443\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000444a = q*b + r
445abs(r) < abs(b)
446r has the same sign as b
Guido van Rossumd38b7641991-01-25 13:26:13 +0000447\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +0000448For example:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000449\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000450>>> divmod(100, 7)
451(14, 2)
452>>> divmod(-100, 7)
453(-15, 5)
454>>> divmod(100, -7)
455(-15, -5)
456>>> divmod(-100, -7)
457(14, -2)
458>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +0000459\end{verbatim}\ecode
Guido van Rossum8ec63501991-02-19 12:53:17 +0000460\funcitem{eval}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +0000461Takes a string as argument and parses and evaluates it as a {\Python}
462expression.
463The expression is executed using the current local and global symbol
464tables.
465Syntax errors are reported as exceptions.
466For example:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000467\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000468>>> x = 1
469>>> eval('x+1')
4702
471>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +0000472\end{verbatim}\ecode
Guido van Rossum8ec63501991-02-19 12:53:17 +0000473\funcitem{exec}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +0000474Takes a string as argument and parses and evaluates it as a sequence of
475{\Python} statements.
476The string should end with a newline (\verb"'\n'").
477The statement is executed using the current local and global symbol
478tables.
479Syntax errors are reported as exceptions.
480For example:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000481\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000482>>> x = 1
483>>> exec('x = x+1\n')
484>>> x
4852
486>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +0000487\end{verbatim}\ecode
Guido van Rossum8ec63501991-02-19 12:53:17 +0000488\funcitem{float}{x}
Guido van Rossum515834a1991-01-22 11:45:29 +0000489Converts a number to floating point.
490The argument may be an integer or floating point number.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000491\funcitem{input}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +0000492Equivalent to
493{\tt eval(raw\_input(s))}.
494As for
495{\tt raw\_input()},
496the argument is optional.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000497\funcitem{int}{x}
498Converts a number to integer.
499The argument may be an integer or floating point number.
500\funcitem{len}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +0000501Returns the length (the number of items) of an object.
502The argument may be a sequence (string, tuple or list) or a mapping
503(dictionary).
Guido van Rossum8ec63501991-02-19 12:53:17 +0000504\funcitem{max}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +0000505Returns the largest item of a non-empty sequence (string, tuple or list).
Guido van Rossum8ec63501991-02-19 12:53:17 +0000506\funcitem{min}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +0000507Returns the smallest item of a non-empty sequence (string, tuple or list).
Guido van Rossum8ec63501991-02-19 12:53:17 +0000508\funcitem{open}{name, mode}
Guido van Rossum515834a1991-01-22 11:45:29 +0000509%.br
510Returns a file object (described earlier under Built-in Types).
511The string arguments are the same as for stdio's
512{\tt fopen()}:
513{\tt 'r'}
514opens the file for reading,
515{\tt 'w'}
516opens it for writing (truncating an existing file),
517{\tt 'a'}
518opens it for appending.%
519\footnote{
520This function should go into a built-in module
521{\tt io}.
522}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000523\funcitem{ord}{c}
524Takes a string of one character and returns its
525ASCII value, e.g., {\tt ord('a')} returns the integer {\tt 97}.
526This is the inverse of {\tt chr()}.
527\funcitem{range}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000528This is a versatile function to create lists containing arithmetic
529progressions of integers.
530With two integer arguments, it returns the ascending sequence of
531integers starting at the first and ending one before the second
532argument.
533A single argument is used as the end point of the sequence, with 0 used
534as the starting point.
535A third argument specifies the step size; negative steps are allowed and
536work as expected, but don't specify a zero step.
537The resulting list may be empty.
538For example:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000539\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000540>>> range(10)
541[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
542>>> range(1, 1+10)
543[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
544>>> range(0, 30, 5)
545[0, 5, 10, 15, 20, 25]
546>>> range(0, 10, 3)
547[0, 3, 6, 9]
548>>> range(0, -10, -1)
549[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
550>>> range(0)
551[]
552>>> range(1, 0)
553[]
554>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +0000555\end{verbatim}\ecode
Guido van Rossum8ec63501991-02-19 12:53:17 +0000556\funcitem{raw\_input}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +0000557%.br
558The argument is optional; if present, it is written to standard output
559without a trailing newline.
560The function then reads a line from input, converts it to a string
561(stripping a trailing newline), and returns that.
562EOF is reported as an exception.
563For example:
Guido van Rossumd38b7641991-01-25 13:26:13 +0000564\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +0000565>>> raw_input('Type anything: ')
Guido van Rossum8ec63501991-02-19 12:53:17 +0000566Type anything: Mutant Teenage Ninja Turtles
567'Mutant Teenage Ninja Turtles'
Guido van Rossum515834a1991-01-22 11:45:29 +0000568>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +0000569\end{verbatim}\ecode
Guido van Rossum8ec63501991-02-19 12:53:17 +0000570\funcitem{reload}{module}
571Causes an already imported module to be re-parsed and re-initialized.
572This is useful if you have edited the module source file and want to
573try out the new version without leaving {\Python}.
574\funcitem{type}{x}
Guido van Rossum515834a1991-01-22 11:45:29 +0000575Returns the type of an object.
576Types are objects themselves:
577the type of a type object is its own type.
578\end{description}
579
580\section{Built-in Modules}
581
582The modules described in this section are built into the interpreter.
583They must be imported using
584{\tt import}.
585Some modules are not always available; it is a configuration option to
586provide them.
587Details are listed with the descriptions, but the best way to see if
588a module exists in a particular implementation is to attempt to import
589it.
590
591\subsection{Built-in Module {\tt sys}}
592
593This module provides access to some variables used or maintained by the
594interpreter and to functions that interact strongly with the interpreter.
595It is always available.
596\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000597\funcitem{argv}
Guido van Rossum515834a1991-01-22 11:45:29 +0000598The list of command line arguments passed to a {\Python} script.
599{\tt sys.argv[0]}
600is the script name.
601If no script name was passed to the {\Python} interpreter,
602{\tt sys.argv}
603is empty.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000604\funcitem{exit}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +0000605Exits from {\Python} with numeric exit status
606{\tt n}.
607This closes all open files and performs other cleanup-actions required by
608the interpreter (but
609{\em finally clauses}
610of
611{\tt try}
612statements are not executed!).
Guido van Rossum8ec63501991-02-19 12:53:17 +0000613\funcitem{modules}
Guido van Rossum515834a1991-01-22 11:45:29 +0000614Gives the list of modules that have already been loaded.
615This can be manipulated to force reloading of modules and other tricks.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000616\funcitem{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000617A list of strings that specifies the search path for modules.
618Initialized from the environment variable {\tt PYTHONPATH}, or an
619installation-dependent default.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000620\funcitem{ps1,~ps2}
Guido van Rossum515834a1991-01-22 11:45:29 +0000621Strings specifying the primary and secondary prompt of the interpreter.
622These are only defined if the interpreter is in interactive mode.
623Their initial values in this case are
624{\tt '>>> '}
625and
626{\tt '... '}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000627\funcitem{stdin, stdout, stderr}
Guido van Rossum515834a1991-01-22 11:45:29 +0000628%.br
629File objects corresponding to the interpreter's standard input, output
630and error streams.
631{\tt sys.stdin}
632is used for all interpreter input except for scripts but including calls
633to
634{\tt input()}
635and
636{\tt raw\_input()}.
637{\tt sys.stdout}
638is used for the output of
639{\tt print} and expression statements
640and for the prompts of
641{\tt input()}
642and
643{\tt raw\_input()}.
644The interpreter's own prompts and its error messages are written to
645stderr.
646Assigning to
647{\tt sys.stderr}
648has no effect on the interpreter; it can be used to write error messages
649to stderr using
650{\tt print}.
651\end{description}
652
653\subsection{Built-in Module {\tt math}}
654
655This module is always available.
656It provides access to the mathematical functions defined by the C
657standard.
658They are:
659{\tt acos(x)},
660{\tt asin(x)},
661{\tt atan(x)},
662{\tt atan2(x,y)},
663{\tt ceil(x)},
664{\tt cos(x)},
665{\tt cosh(x)},
666{\tt exp(x)},
667{\tt fabs(x)},
668{\tt floor(x)},
669%{\tt fmod(...)} XXX not yet
670%{\tt frexp(...)} XXX not yet
671%{\tt ldexp(...)} XXX not yet
672{\tt log(x)},
673{\tt log10(x)},
674%{\tt modf(...)} XXX not yet
675{\tt pow(x,y)},
676{\tt sin(x)},
677{\tt sinh(x)},
678{\tt sqrt(x)},
679{\tt tan(x)},
680{\tt tanh(x)}.
681
682It also defines two mathematical constants:
683{\tt pi}
684and
685{\tt e}.
686
687\subsection{Built-in Module {\tt time}}
688
689This module provides various time-related functions.
690It is always available.
691Functions are:
692\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000693\funcitem{sleep}{secs}
Guido van Rossum515834a1991-01-22 11:45:29 +0000694Suspends execution for the given number of seconds.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000695\funcitem{time}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000696Returns the time in seconds since the Epoch (Thursday January 1,
69700:00:00, 1970 UCT on \UNIX\ machines).
698\end{description}
699
700\noindent
701In some versions (Amoeba, Mac) the following functions also exist:
702\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000703\funcitem{millisleep}{msecs}
Guido van Rossum515834a1991-01-22 11:45:29 +0000704Suspends execution for the given number of milliseconds.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000705\funcitem{millitimer}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000706Returns the number of milliseconds of real time elapsed since some point
707in the past that is fixed per execution of the python interpreter (but
708may change in each following run).
709\end{description}
710
711\noindent
712The granularity of the milliseconds functions may be more than a
713millisecond (100 msecs on Amoeba, 1/60 sec on the Mac).
714
Guido van Rossum8ec63501991-02-19 12:53:17 +0000715\subsection{Built-in Module {\tt regexp}}
716
717This module provides a regular expression matching operation.
718It is always available.
719
720The module defines a function and an exception:
721
722\begin{description}
723
724\funcitem{compile}{pattern}
725
726Compile a regular expression given as a string into a regular
727expression object.
728The string must be an egrep-style regular expression;
729this means that the characters {\tt '(' ')' '*' '+' '?' '|' '^' '$'}
730are special.
731(It is implemented using Henry Spencer's regular expression matching
732functions.)
733
734excitem{error}{regexp.error}
735
736Exception raised when a string passed to {\tt compile()} is not a
737valid regular expression (e.g., unmatched parentheses) or when some other
738error occurs during compilation or matching
739(``no match found'' is not an error).
740
741\end{description}
742
743Compiled regular expression objects support a single method:
744
745\begin{description}
746
747\funcitem{exec}{str}
748
749Find the first occurrence of the compiled regular expression in the
750string {\tt str}.
751The return value is a tuple of pairs specifying where a match was
752found and where matches were found for subpatterns specified with
753{\tt '('} and {\tt ')'} in the pattern.
754If no match is found, an empty tuple is returned; otherwise the first
755item of the tuple is a pair of slice indices into the search string
756giving the match found.
757If there were any subpatterns in the pattern, the returned tuple has an
758additional item for each subpattern, giving the slice indices into the
759search string where that subpattern was found.
760
761\end{description}
762
763For example:
764\bcode\begin{verbatim}
765>>> import regexp
766>>> r = regexp.compile('--(.*)--')
767>>> s = 'a--b--c'
768>>> r.exec(s)
769((1, 6), (3, 4))
770>>> s[1:6] # The entire match
771'--b--'
772>>> s[3:4] # The subpattern
773'b'
774>>>
775\end{verbatim}\ecode
776
Guido van Rossum515834a1991-01-22 11:45:29 +0000777\subsection{Built-in Module {\tt posix}}
778
779This module provides access to operating system functionality that is
780standardized by the C Standard and the POSIX standard (a thinly diguised
781{\UNIX} interface).
782It is available in all {\Python} versions except on the Macintosh.
783Errors are reported exceptions.
784It defines the following items:
785\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000786\funcitem{chdir}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000787Changes the current directory to
788{\tt path}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000789\funcitem{chmod}{path, mode}
Guido van Rossum515834a1991-01-22 11:45:29 +0000790Change the mode of
791{\tt path}
792to the numeric
793{\tt mode}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000794\funcitem{environ}
Guido van Rossum515834a1991-01-22 11:45:29 +0000795A dictionary representing the string environment at the time
796the interpreter was started.
797(Modifying this dictionary does not affect the string environment of the
798interpreter.)
799For example,
800{\tt posix.environ['HOME']}
801is the pathname of your home directory, equivalent to
802{\tt getenv("HOME")}
803in C.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000804\excitem{error}{posix.error}
Guido van Rossum515834a1991-01-22 11:45:29 +0000805%.br
806The exception raised when an POSIX function returns an error.
807The value accompanying this exception is a pair containing the numeric
808error code from
809{\tt errno}
810and the corresponding string, as would be printed by the C function
811{\tt perror()}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000812\funcitem{getcwd}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000813Returns a string representing the current working directory.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000814\funcitem{link}{src, dst}
Guido van Rossum515834a1991-01-22 11:45:29 +0000815Creates a hard link pointing to
816{\tt src}
817named
818{\tt dst}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000819\funcitem{listdir}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000820Returns a list containing the names of the entries in the
821directory.
822The list is in arbitrary order.
823It includes the special entries
824{\tt '.'}
825and
826{\tt '..'}
827if they are present in the directory.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000828\funcitem{mkdir}{path, mode}
Guido van Rossum515834a1991-01-22 11:45:29 +0000829Creates a directory named
830{\tt path}
831with numeric mode
832{\tt mode}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000833\funcitem{rename}{src, dst}
Guido van Rossum515834a1991-01-22 11:45:29 +0000834Renames the file or directory
835{\tt src}
836to
837{\tt dst}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000838\funcitem{rmdir}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000839Removes the directory
840{\tt path}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000841\funcitem{stat}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000842Performs a
843{\em stat}
844system call on the given path.
845The return value is a tuple of at least 10 integers giving the most
846important (and portable) members of the
847{\em stat}
848structure, in the order
849{\tt st\_mode},
850{\tt st\_ino},
851{\tt st\_dev},
852{\tt st\_nlink},
853{\tt st\_uid},
854{\tt st\_gid},
855{\tt st\_size},
856{\tt st\_atime},
857{\tt st\_mtime},
858{\tt st\_ctime}.
859More items may be added at the end by some implementations.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000860\funcitem{system}{command}
Guido van Rossum515834a1991-01-22 11:45:29 +0000861Executes the command (a string) in a subshell.
862This is implemented by calling the Standard C function
863{\tt system()},
864and has the same limitations.
865Changes to
866{\tt posix.environ},
867{\tt sys.stdin}
868etc. are not reflected in the environment of the executed command.
869The return value is the exit status of the process as returned by
870Standard C
871{\tt system()}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000872\funcitem{umask}{mask}
Guido van Rossum515834a1991-01-22 11:45:29 +0000873Sets the current numeric umask and returns the previous umask.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000874\funcitem{unlink}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000875Unlinks the file
876{\tt path}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000877\funcitem{utimes(path, }{atime, mtime)}
Guido van Rossum515834a1991-01-22 11:45:29 +0000878%.br
879Sets the access and modified time of the file to the given values.
880(The second argument is a tuple of two items.)
881\end{description}
882
883The following functions are only available on systems that support
884symbolic links:
885\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000886\funcitem{lstat}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000887Like
888{\tt stat()},
889but does not follow symbolic links.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000890\funcitem{readlink}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +0000891Returns a string representing the path to which the symbolic link
892points.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000893\funcitem{symlink}{src, dst}
Guido van Rossum515834a1991-01-22 11:45:29 +0000894Creates a symbolic link pointing to
895{\tt src}
896named
897{\tt dst}.
898\end{description}
899
900\subsection{Built-in Module {\tt stdwin}}
901
902This module defines several new object types and functions that
903provide access to the functionality of the Standard Window System
904Interface, STDWIN [CWI report CR-R8817].
905It is available on systems to which STDWIN has been ported (which is
906most systems).
907It is only available if the {\tt DISPLAY} environment variable is set
908or an explicit `{\tt -display \it displayname}' argument is passed to
909the interpreter.
910
911Functions have names that usually resemble their C STDWIN counterparts
912with the initial `w' dropped.
913Points are represented by pairs of integers; rectangles
914by pairs of points.
915For a complete description of STDWIN please refer to the documentation
916of STDWIN for C programmers (aforementioned CWI report).
917\subsubsection{Functions Defined in Module {\tt stdwin}}
918
919The following functions are defined in the {\tt stdwin} module:
920\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000921\funcitem{open}{title}
Guido van Rossum515834a1991-01-22 11:45:29 +0000922%.br
923Opens a new window whose initial title is given by the string argument.
924Returns a window object; window object methods are described below.%
925\footnote{
926The {\Python} version of STDWIN does not support draw procedures; all
927drawing requests are reported as draw events.
928}
Guido van Rossum8ec63501991-02-19 12:53:17 +0000929\funcitem{getevent}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000930%.br
931Waits for and returns the next event.
932An event is returned as a triple: the first element is the event
933type, a small integer; the second element is the window object to which
934the event applies, or
935{\tt None}
936if it applies to no window in particular;
937the third element is type-dependent.
938Names for event types and command codes are defined in the standard
939module
940{\tt stdwinevent}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000941\funcitem{setdefwinpos}{h, v}
Guido van Rossum515834a1991-01-22 11:45:29 +0000942%.br
943Sets the default window position.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000944\funcitem{setdefwinsize}{width, height}
Guido van Rossum515834a1991-01-22 11:45:29 +0000945%.br
946Sets the default window size.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000947\funcitem{menucreate}{title}
Guido van Rossum515834a1991-01-22 11:45:29 +0000948%.br
949Creates a menu object referring to a global menu (a menu that appears in
950all windows).
951Methods of menu objects are described below.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000952\funcitem{fleep}{}
Guido van Rossum515834a1991-01-22 11:45:29 +0000953%.br
954Causes a beep or bell (or perhaps a `visual bell' or flash, hence the
955name).
Guido van Rossum8ec63501991-02-19 12:53:17 +0000956\funcitem{message}{string}
Guido van Rossum515834a1991-01-22 11:45:29 +0000957%.br
958Displays a dialog box containing the string.
959The user must click OK before the function returns.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000960\funcitem{askync}{prompt, default}
Guido van Rossum515834a1991-01-22 11:45:29 +0000961%.br
962Displays a dialog that prompts the user to answer a question with yes or
963no.
964The function returns 0 for no, 1 for yes.
965If the user hits the Return key, the default (which must be 0 or 1) is
966returned.
967If the user cancels the dialog, the
968{\tt KeyboardInterrupt}
969exception is raised.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000970\funcitem{askstr}{prompt, default}
Guido van Rossum515834a1991-01-22 11:45:29 +0000971%.br
972Displays a dialog that prompts the user for a string.
973If the user hits the Return key, the default string is returned.
974If the user cancels the dialog, the
975{\tt KeyboardInterrupt}
976exception is raised.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000977\funcitem{askfile}{prompt, default, new}
Guido van Rossum515834a1991-01-22 11:45:29 +0000978%.br
979Asks the user to specify a filename.
980If
981{\tt new}
982is zero it must be an existing file; otherwise, it must be a new file.
983If the user cancels the dialog, the
984{\tt KeyboardInterrupt}
985exception is raised.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000986\funcitem{setcutbuffer}{i, string}
Guido van Rossum515834a1991-01-22 11:45:29 +0000987%.br
988Stores the string in the system's cut buffer number
989{\tt i},
990where it can be found (for pasting) by other applications.
991On X11, there are 8 cut buffers (numbered 0..7).
992Cut buffer number 0 is the `clipboard' on the Macintosh.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000993\funcitem{getcutbuffer}{i}
Guido van Rossum515834a1991-01-22 11:45:29 +0000994%.br
995Returns the contents of the system's cut buffer number
996{\tt i}.
Guido van Rossum8ec63501991-02-19 12:53:17 +0000997\funcitem{rotatebutbuffers}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +0000998%.br
999On X11, this rotates the 8 cut buffers by
1000{\tt n}.
1001Ignored on the Macintosh.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001002\funcitem{getselection}{i}
Guido van Rossum515834a1991-01-22 11:45:29 +00001003%.br
1004Returns X11 selection number
1005{\tt i.}
1006Selections are not cut buffers.
1007Selection numbers are defined in module
1008{\tt stdwinevents}.
1009Selection {\tt WS\_PRIMARY} is the
1010{\em primary}
1011selection (used by
1012xterm,
1013for instance);
1014selection {\tt WS\_SECONDARY} is the
1015{\em secondary}
1016selection; selection {\tt WS\_CLIPBOARD} is the
1017{\em clipboard}
1018selection (used by
1019xclipboard).
1020On the Macintosh, this always returns an empty string.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001021\funcitem{resetselection}{i}
Guido van Rossum515834a1991-01-22 11:45:29 +00001022%.br
1023Resets selection number
1024{\tt i},
1025if this process owns it.
1026(See window method
1027{\tt setselection()}).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001028\funcitem{baseline}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001029%.br
1030Return the baseline of the current font (defined by STDWIN as the
1031vertical distance between the baseline and the top of the
1032characters).%
1033\footnote{
1034There is no way yet to set the current font.
1035This will change in a future version.
1036}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001037\funcitem{lineheight}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001038%.br
1039Return the total line height of the current font.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001040\funcitem{textbreak}{str, width}
Guido van Rossum515834a1991-01-22 11:45:29 +00001041%.br
1042Return the number of characters of the string that fit into a space of
1043{\tt width}
1044bits wide when drawn in the curent font.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001045\funcitem{textwidth}{str}
Guido van Rossum515834a1991-01-22 11:45:29 +00001046%.br
1047Return the width in bits of the string when drawn in the current font.
Guido van Rossum515834a1991-01-22 11:45:29 +00001048\end{description}
1049
Guido van Rossumd38b7641991-01-25 13:26:13 +00001050\subsubsection{Window Object Methods}
1051
Guido van Rossum515834a1991-01-22 11:45:29 +00001052Window objects are created by
1053{\tt stdwin.open()}.
1054There is no explicit function to close a window; windows are closed when
1055they are garbage-collected.
1056Window objects have the following methods:
1057\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001058\funcitem{begindrawing}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001059Returns a drawing object, whose methods (described below) allow drawing
1060in the window.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001061\funcitem{change}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001062Invalidates the given rectangle; this may cause a draw event.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001063\funcitem{gettitle}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001064Returns the window's title string.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001065\funcitem{getdocsize}{}
Guido van Rossumd38b7641991-01-25 13:26:13 +00001066\begin{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001067Returns a pair of integers giving the size of the document as set by
1068{\tt setdocsize()}.
Guido van Rossumd38b7641991-01-25 13:26:13 +00001069\end{sloppypar}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001070\funcitem{getorigin}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001071Returns a pair of integers giving the origin of the window with respect
1072to the document.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001073\funcitem{getwinsize}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001074Returns a pair of integers giving the size of the window.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001075\funcitem{menucreate}{title}
Guido van Rossum515834a1991-01-22 11:45:29 +00001076Creates a menu object referring to a local menu (a menu that appears
1077only in this window).
1078Methods menu objects are described below.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001079\funcitem{scroll}{rect,~point}
Guido van Rossum515834a1991-01-22 11:45:29 +00001080Scrolls the given rectangle by the vector given by the point.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001081\funcitem{setwincursor}{name}
Guido van Rossumd38b7641991-01-25 13:26:13 +00001082\begin{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001083Sets the window cursor to a cursor of the given name.
1084It raises the
1085{\tt Runtime\-Error}
1086exception if no cursor of the given name exists.
1087Suitable names are
1088{\tt 'ibeam'},
1089{\tt 'arrow'},
1090{\tt 'cross'},
1091{\tt 'watch'}
1092and
1093{\tt 'plus'}.
1094On X11, there are many more (see
1095{\tt <X11/cursorfont.h>}).
Guido van Rossumd38b7641991-01-25 13:26:13 +00001096\end{sloppypar}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001097\funcitem{setdocsize}{point}
Guido van Rossum515834a1991-01-22 11:45:29 +00001098Sets the size of the drawing document.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001099\funcitem{setorigin}{point}
Guido van Rossum515834a1991-01-22 11:45:29 +00001100Moves the origin of the window to the given point in the document.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001101\funcitem{setselection}{i, str}
Guido van Rossum515834a1991-01-22 11:45:29 +00001102Attempts to set X11 selection number
1103{\tt i}
1104to the string
1105{\tt str}.
1106(See stdwin method
1107{\tt getselection()}
1108for the meaning of
1109{\tt i}.)
1110Returns true if it succeeds.
1111If it succeeds, the window ``owns'' the selection until
1112(a) another applications takes ownership of the selection; or
1113(b) the window is deleted; or
1114(c) the application clears ownership by calling
1115{\tt stdwin.resetselection(i)}.
1116When another application takes ownership of the selection, a
1117{\tt WE\_LOST\_SEL}
1118event is received for no particular window and with the selection number
1119as detail.
1120Ignored on the Macintosh.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001121\funcitem{settitle}{title}
Guido van Rossum515834a1991-01-22 11:45:29 +00001122Sets the window's title string.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001123\funcitem{settimer}{dsecs}
Guido van Rossum515834a1991-01-22 11:45:29 +00001124Schedules a timer event for the window in
1125{\tt dsecs/10}
1126seconds.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001127\funcitem{show}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001128Tries to ensure that the given rectangle of the document is visible in
1129the window.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001130\funcitem{textcreate}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001131Creates a text-edit object in the document at the given rectangle.
1132Methods of text-edit objects are described below.
1133\end{description}
1134
1135\subsubsection{Drawing Object Methods}
1136
1137Drawing objects are created exclusively by the window method
1138{\tt begindrawing()}.
1139Only one drawing object can exist at any given time; the drawing object
1140must be deleted to finish drawing.
1141No drawing object may exist when
1142{\tt stdwin.getevent()}
1143is called.
1144Drawing objects have the following methods:
1145\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001146\funcitem{box}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001147Draws a box around a rectangle.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001148\funcitem{circle}{center, radius}
Guido van Rossum515834a1991-01-22 11:45:29 +00001149%.br
1150Draws a circle with given center point and radius.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001151\funcitem{elarc(center, (rh, rv), }{a1, a2)}
Guido van Rossum515834a1991-01-22 11:45:29 +00001152%.br
1153Draws an elliptical arc with given center point.
1154{\tt (rh, rv)}
1155gives the half sizes of the horizontal and vertical radii.
1156{\tt (a1, a2)}
1157gives the angles (in degrees) of the begin and end points.
11580 degrees is at 3 o'clock, 90 degrees is at 12 o'clock.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001159\funcitem{erase}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001160Erases a rectangle.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001161\funcitem{invert}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001162Inverts a rectangle.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001163\funcitem{line}{p1, p2}
Guido van Rossum515834a1991-01-22 11:45:29 +00001164Draws a line from point
1165{\tt p1}
1166to
1167{\tt p2}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001168\funcitem{paint}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001169Fills a rectangle.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001170\funcitem{text}{p, str}
Guido van Rossum515834a1991-01-22 11:45:29 +00001171Draws a string starting at point p (the point specifies the
1172top left coordinate of the string).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001173\funcitem{shade}{rect, percent}
Guido van Rossum515834a1991-01-22 11:45:29 +00001174%.br
1175Fills a rectangle with a shading pattern that is about
1176{\tt percent}
1177percent filled.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001178\funcitem{xorline}{p1, p2}
Guido van Rossum515834a1991-01-22 11:45:29 +00001179Draws a line in XOR mode.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001180\funcitem{baseline(), lineheight(), textbreak(), textwidth}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001181%.br
1182These functions are similar to the corresponding functions described
1183above for the
1184{\tt stdwin}
1185module, but use the current font of the window instead of the (global)
1186default font.
1187\end{description}
1188
1189\subsubsection{Menu Object Methods}
1190
1191A menu object represents a menu.
1192The menu is destroyed when the menu object is deleted.
1193The following methods are defined:
1194\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001195\funcitem{additem}{text, shortcut}
Guido van Rossum515834a1991-01-22 11:45:29 +00001196%.br
1197Adds a menu item with given text.
1198The shortcut must be a string of length 1, or omitted (to specify no
1199shortcut).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001200\funcitem{setitem}{i, text}
Guido van Rossum515834a1991-01-22 11:45:29 +00001201Sets the text of item number
1202{\tt i}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001203\funcitem{enable}{i, flag}
Guido van Rossum515834a1991-01-22 11:45:29 +00001204Enables or disables item
1205{\tt i}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001206\funcitem{check}{i, flag}
Guido van Rossum515834a1991-01-22 11:45:29 +00001207Sets or clears the
1208{\em check mark}
1209for item
1210{\tt i}.
1211\end{description}
1212
1213\subsubsection{Text-edit Object Methods}
1214
1215A text-edit object represents a text-edit block.
1216For semantics, see the STDWIN documentation for C programmers.
1217The following methods exist:
1218\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001219\funcitem{arrow}{code}
Guido van Rossum515834a1991-01-22 11:45:29 +00001220Passes an arrow event to the text-edit block.
1221The
1222{\tt code}
1223must be one of
1224{\tt WC\_LEFT},
1225{\tt WC\_RIGHT},
1226{\tt WC\_UP}
1227or
1228{\tt WC\_DOWN}
1229(see module
1230{\tt stdwinevents}).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001231\funcitem{draw}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001232Passes a draw event to the text-edit block.
1233The rectangle specifies the redraw area.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001234\funcitem{event}{type, window, detail}
Guido van Rossum515834a1991-01-22 11:45:29 +00001235%.br
1236Passes an event gotten from
1237{\tt stdwin.getevent()}
1238to the text-edit block.
1239Returns true if the event was handled.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001240\funcitem{getfocus}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001241Returns 2 integers representing the start and end positions of the
1242focus, usable as slice indices on the string returned by
1243{\tt getfocustext()}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001244\funcitem{getfocustext}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001245Returns the text in the focus.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001246\funcitem{getrect}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001247Returns a rectangle giving the actual position of the text-edit block.
1248(The bottom coordinate may differ from the initial position because
1249the block automatically shrinks or grows to fit.)
Guido van Rossum8ec63501991-02-19 12:53:17 +00001250\funcitem{gettext}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001251Returns the entire text buffer.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001252\funcitem{move}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00001253Specifies a new position for the text-edit block in the document.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001254\funcitem{replace}{str}
Guido van Rossum515834a1991-01-22 11:45:29 +00001255Replaces the focus by the given string.
1256The new focus is an insert point at the end of the string.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001257\funcitem{setfocus}{i,~j}
Guido van Rossum515834a1991-01-22 11:45:29 +00001258Specifies the new focus.
1259Out-of-bounds values are silently clipped.
1260\end{description}
1261
Guido van Rossum8ec63501991-02-19 12:53:17 +00001262\subsubsection{Example}
1263
1264Here is a simple example of using STDWIN in Python.
1265It creates a window and draws the string ``Hello world'' in the top
1266left corner of the window.
1267The window will be correctly redrawn when covered and re-exposed.
1268The program quits when the close icon or menu item is requested.
1269\bcode\begin{verbatim}
1270import stdwin
1271from stdwinevents import *
1272
1273def main():
1274 mywin = stdwin.open('Hello')
1275 #
1276 while 1:
1277 (type, win, detail) = stdwin.getevent()
1278 if type = WE_DRAW:
1279 draw = win.begindrawing()
1280 draw.text((0, 0), 'Hello, world')
1281 del draw
1282 elif type = WE_CLOSE:
1283 break
1284
1285main()
1286\end{verbatim}\ecode
1287
Guido van Rossum515834a1991-01-22 11:45:29 +00001288\subsection{Built-in Module {\tt amoeba}}
1289
1290This module provides some object types and operations useful for
1291Amoeba applications.
1292It is only available on systems that support Amoeba operations.
1293RPC errors and other Amoeba errors are reported as the exception
1294{\tt amoeba.error = 'amoeba.error'}.
1295The module
1296{\tt amoeba}
1297defines the following items:
1298\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001299\funcitem{name\_append}{path,~cap}
Guido van Rossum515834a1991-01-22 11:45:29 +00001300%.br
1301Stores a capability in the Amoeba directory tree.
1302Arguments are the pathname (a string) and the capability (a capability
1303object as returned by
1304{\tt name\_lookup()}).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001305\funcitem{name\_delete}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +00001306%.br
1307Deletes a capability from the Amoeba directory tree.
1308Argument is the pathname.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001309\funcitem{name\_lookup}{path}
Guido van Rossum515834a1991-01-22 11:45:29 +00001310%.br
1311Looks up a capability.
1312Argument is the pathname.
1313Returns a
1314{\em capability}
1315object, to which various interesting operations apply, described below.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001316\funcitem{name\_replace}{path,~cap}
Guido van Rossum515834a1991-01-22 11:45:29 +00001317%.br
1318Replaces a capability in the Amoeba directory tree.
1319Arguments are the pathname and the new capability.
1320(This differs from
1321{\tt name\_append()}
1322in the behavior when the pathname already exists:
1323{\tt name\_append()}
1324finds this an error while
1325{\tt name\_replace()}
1326allows it, as its name suggests.)
Guido van Rossum8ec63501991-02-19 12:53:17 +00001327\funcitem{capv}
Guido van Rossum515834a1991-01-22 11:45:29 +00001328A table representing the capability environment at the time the
1329interpreter was started.
1330(Alas, modifying this table does not affect the capability environment
1331of the interpreter.)
1332For example,
1333{\tt amoeba.capv['ROOT']}
1334is the capability of your root directory, similar to
1335{\tt getcap("ROOT")}
1336in C.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001337\excitem{error}{amoeba.error}
Guido van Rossum515834a1991-01-22 11:45:29 +00001338%.br
1339The exception raised when an Amoeba function returns an error.
1340The value accompanying this exception is a pair containing the numeric
1341error code and the corresponding string, as returned by the C function
1342{\tt err\_why()}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001343\funcitem{timeout}{msecs}
Guido van Rossum515834a1991-01-22 11:45:29 +00001344%.br
1345Sets the transaction timeout, in milliseconds.
1346Returns the previous timeout.
1347Initially, the timeout is set to 2 seconds by the {\Python} interpreter.
1348\end{description}
1349
1350\subsubsection{Capability Operations}
1351
1352Capabilities are written in a convenient ASCII format, also used by the
1353Amoeba utilities
1354{\em c2a}(U)
1355and
1356{\em a2c}(U).
1357For example:
Guido van Rossumd38b7641991-01-25 13:26:13 +00001358\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001359>>> amoeba.name_lookup('/profile/cap')
1360aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a
1361>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +00001362\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001363The following methods are defined for capability objects.
1364\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001365\funcitem{dir\_list}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001366Returns a list of the names of the entries in an Amoeba directory.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001367\funcitem{b\_read}{offset, maxsize}
Guido van Rossum515834a1991-01-22 11:45:29 +00001368%.br
1369Reads (at most)
1370{\tt maxsize}
1371bytes from a bullet file at offset
1372{\tt offset.}
1373The data is returned as a string.
1374EOF is reported as an empty string.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001375\funcitem{b\_size}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001376Returns the size of a bullet file.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001377\funcitem{dir\_append(), dir\_delete(), dir\_lookup(), dir\_replace}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001378%.br
Guido van Rossumd38b7641991-01-25 13:26:13 +00001379\itembreak
Guido van Rossum515834a1991-01-22 11:45:29 +00001380Like the corresponding
1381{\tt name\_*}
1382functions, but with a path relative to the capability.
1383(For paths beginning with a slash the capability is ignored, since this
1384is the defined semantics for Amoeba.)
Guido van Rossum8ec63501991-02-19 12:53:17 +00001385\funcitem{std\_info}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001386Returns the standard info string of the object.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001387\funcitem{tod\_gettime}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001388Returns the time (in seconds since the Epoch, in UCT, as for POSIX) from
1389a time server.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001390\funcitem{tod\_settime}{t}
Guido van Rossum515834a1991-01-22 11:45:29 +00001391Sets the time kept by a time server.
1392\end{description}
1393
1394\subsection{Built-in Module {\tt audio}}
1395
1396This module provides rudimentary access to the audio I/O device
1397{\tt /dev/audio}
1398on the Silicon Graphics Personal IRIS; see audio(7).
1399It supports the following operations:
1400\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001401\funcitem{setoutgain}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +00001402Sets the output gain (0-255).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001403\funcitem{getoutgain}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001404Returns the output gain.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001405\funcitem{setrate}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +00001406Sets the sampling rate: 1=32K/sec, 2=16K/sec, 3=8K/sec.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001407\funcitem{setduration}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +00001408Sets the `sound duration' in units of 1/100 seconds.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001409\funcitem{read}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +00001410Reads a chunk of
1411{\tt n}
1412sampled bytes from the audio input (line in or microphone).
1413The chunk is returned as a string of length n.
1414Each byte encodes one sample as a signed 8-bit quantity using linear
1415encoding.
1416This string can be converted to numbers using {\tt chr2num()} described
1417below.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001418\funcitem{write}{buf}
Guido van Rossum515834a1991-01-22 11:45:29 +00001419Writes a chunk of samples to the audio output (speaker).
1420\end{description}
1421
1422These operations support asynchronous audio I/O:
1423\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001424\funcitem{start\_recording}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +00001425%.br
1426Starts a second thread (a process with shared memory) that begins reading
1427{\tt n}
1428bytes from the audio device.
1429The main thread immediately continues.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001430\funcitem{wait\_recording}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001431%.br
1432Waits for the second thread to finish and returns the data read.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001433\funcitem{stop\_recording}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001434%.br
1435Makes the second thread stop reading as soon as possible.
1436Returns the data read so far.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001437\funcitem{poll\_recording}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001438%.br
1439Returns true if the second thread has finished reading (so
1440{\tt wait\_recording()} would return the data without delay).
1441\item[{\tt start\_playing(chunk)}, {\tt wait\_playing()},
1442{\tt stop\_playing()}, {\tt poll\_playing()}]
1443%.br
Guido van Rossumd38b7641991-01-25 13:26:13 +00001444\begin{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001445Similar but for output.
1446{\tt stop\_playing()}
1447returns a lower bound for the number of bytes actually played (not very
1448accurate).
Guido van Rossumd38b7641991-01-25 13:26:13 +00001449\end{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001450\end{description}
1451
1452The following operations do not affect the audio device but are
1453implemented in C for efficiency:
1454\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001455\funcitem{amplify}{buf, f1, f2}
Guido van Rossum515834a1991-01-22 11:45:29 +00001456%.br
1457Amplifies a chunk of samples by a variable factor changing from
1458{\tt f1}/256 to {\tt f2}/256.
1459Negative factors are allowed.
1460Resulting values that are to large to fit in a byte are clipped.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001461\funcitem{reverse}{buf}
Guido van Rossum515834a1991-01-22 11:45:29 +00001462%.br
1463Returns a chunk of samples backwards.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001464\funcitem{add}{buf1, buf2}
Guido van Rossum515834a1991-01-22 11:45:29 +00001465%.br
1466Bytewise adds two chunks of samples.
1467Bytes that exceed the range are clipped.
1468If one buffer shorter, it is assumed to be padded with zeros.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001469\funcitem{chr2num}{buf}
Guido van Rossum515834a1991-01-22 11:45:29 +00001470%.br
1471Converts a string of sampled bytes as returned by {\tt read()} into
1472a list containing the numeric values of the samples.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001473\funcitem{num2chr}{list}
Guido van Rossum515834a1991-01-22 11:45:29 +00001474%.br
Guido van Rossumd38b7641991-01-25 13:26:13 +00001475\begin{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001476Converts a list as returned by
1477{\tt chr2num()}
1478back to a buffer acceptable by
1479{\tt write()}.
Guido van Rossumd38b7641991-01-25 13:26:13 +00001480\end{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001481\end{description}
1482
1483\subsection{Built-in Module {\tt gl}}
1484
1485This module provides access to the Silicon Graphics
1486{\em Graphics Library}.
1487It is available only on Silicon Graphics machines.
1488
1489{\bf Warning:}
1490Some illegal calls to the GL library cause the {\Python} interpreter to dump
1491core.
1492In particular, the use of most GL calls is unsafe before the first
1493window is opened.
1494
1495The module is too large to document here in its entirety, but the
1496following should help you to get started.
1497The parameter conventions for the C functions are translated to {\Python} as
1498follows:
1499
1500\begin{itemize}
1501\item
1502All (short, long, unsigned) int values are represented by {\Python}
1503integers.
1504\item
1505All float and double values are represented by {\Python} floating point
1506numbers.
1507In most cases, {\Python} integers are also allowed.
1508\item
1509All arrays are represented by one-dimensional {\Python} lists.
1510In most cases, tuples are also allowed.
1511\item
Guido van Rossumd38b7641991-01-25 13:26:13 +00001512\begin{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001513All string and character arguments are represented by {\Python} strings,
Guido van Rossumd38b7641991-01-25 13:26:13 +00001514for instance,
Guido van Rossum515834a1991-01-22 11:45:29 +00001515{\tt winopen('Hi~There!')}
1516and
1517{\tt rotate(900,~'z')}.
Guido van Rossumd38b7641991-01-25 13:26:13 +00001518\end{sloppypar}
Guido van Rossum515834a1991-01-22 11:45:29 +00001519\item
1520All (short, long, unsigned) integer arguments or return values that are
1521only used to specify the length of an array argument are omitted.
1522For example, the C call
Guido van Rossumd38b7641991-01-25 13:26:13 +00001523\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001524lmdef(deftype, index, np, props)
Guido van Rossumd38b7641991-01-25 13:26:13 +00001525\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001526is translated to {\Python} as
Guido van Rossumd38b7641991-01-25 13:26:13 +00001527\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001528lmdef(deftype, index, props)
Guido van Rossumd38b7641991-01-25 13:26:13 +00001529\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001530\item
1531Output arguments are omitted from the argument list; they are
1532transmitted as function return values instead.
1533If more than one value must be returned, the return value is a tuple.
1534If the C function has both a regular return value (that is not omitted
1535because of the previous rule) and an output argument, the return value
1536comes first in the tuple.
1537Examples: the C call
Guido van Rossumd38b7641991-01-25 13:26:13 +00001538\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001539getmcolor(i, &red, &green, &blue)
Guido van Rossumd38b7641991-01-25 13:26:13 +00001540\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001541is translated to {\Python} as
Guido van Rossumd38b7641991-01-25 13:26:13 +00001542\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001543red, green, blue = getmcolor(i)
Guido van Rossumd38b7641991-01-25 13:26:13 +00001544\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001545\end{itemize}
1546
1547The following functions are non-standard or have special argument
1548conventions:
1549\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001550\funcitem{varray}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001551Equivalent to but faster than a number of
1552{\tt v3d()}
1553calls.
1554The argument is a list (or tuple) of points.
1555Each point must be a tuple of coordinates (x, y, z) or (x, y).
1556The points may be 2- or 3-dimensional but must all have the
1557same dimension.
1558Float and int values may be mixed however.
1559The points are always converted to 3D double precision points
1560by assuming z=0.0 if necessary (as indicated in the man page),
1561and for each point
1562{\tt v3d()}
1563is called.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001564\funcitem{nvarray}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001565Equivalent to but faster than a number of
1566{\tt n3f}
1567and
1568{\tt v3f}
1569calls.
1570The argument is an array (list or tuple) of pairs of normals and points.
1571Each pair is a tuple of a point and a normal for that point.
1572Each point or normal must be a tuple of coordinates (x, y, z).
1573Three coordinates must be given.
1574Float and int values may be mixed.
1575For each pair,
1576{\tt n3f()}
1577is called for the normal, and then
1578{\tt v3f()}
1579is called for the point.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001580\funcitem{vnarray}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001581Similar to
1582{\tt nvarray()}
1583but the pairs have the point first and the normal second.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001584\funcitem{nurbssurface}{s\_k[], t\_k[], ctl[][], s\_ord, t\_ord, type}
Guido van Rossum515834a1991-01-22 11:45:29 +00001585%.br
Guido van Rossumd38b7641991-01-25 13:26:13 +00001586\itembreak
Guido van Rossum515834a1991-01-22 11:45:29 +00001587Defines a nurbs surface.
1588The dimensions of
1589{\tt ctl[][]}
1590are computed as follows:
1591{\tt [len(s\_k)~-~s\_ord]},
1592{\tt [len(t\_k)~-~t\_ord]}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001593\funcitem{nurbscurve}{knots, ctlpoints, order, type}
Guido van Rossum515834a1991-01-22 11:45:29 +00001594%.br
1595Defines a nurbs curve.
1596The length of ctlpoints is
1597{\tt len(knots)~-~order}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001598\funcitem{pwlcurve}{points, type}
Guido van Rossum515834a1991-01-22 11:45:29 +00001599%.br
1600Defines a piecewise-linear curve.
1601{\tt points}
1602is a list of points.
1603{\tt type}
1604must be
1605{\tt N\_ST}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001606\funcitem{pick(n), select}{n}
Guido van Rossum515834a1991-01-22 11:45:29 +00001607%.br
1608The only argument to these functions specifies the desired size of the
1609pick or select buffer.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001610\funcitem{endpick(), endselect}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001611%.br
1612These functions have no arguments.
1613They return a list of integers representing the used part of the
1614pick/select buffer.
1615No method is provided to detect buffer overrun.
1616\end{description}
1617
1618Here is a tiny but complete example GL program in {\Python}:
Guido van Rossumd38b7641991-01-25 13:26:13 +00001619\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001620import gl, GL, time
1621
1622def main():
1623 gl.foreground()
1624 gl.prefposition(500, 900, 500, 900)
1625 w = gl.winopen('CrissCross')
1626 gl.ortho2(0.0, 400.0, 0.0, 400.0)
1627 gl.color(GL.WHITE)
1628 gl.clear()
1629 gl.color(GL.RED)
1630 gl.bgnline()
1631 gl.v2f(0.0, 0.0)
1632 gl.v2f(400.0, 400.0)
1633 gl.endline()
1634 gl.bgnline()
1635 gl.v2f(400.0, 0.0)
1636 gl.v2f(0.0, 400.0)
1637 gl.endline()
1638 time.sleep(5)
1639
1640main()
Guido van Rossumd38b7641991-01-25 13:26:13 +00001641\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001642
1643\subsection{Built-in Module {\tt pnl}}
1644
1645This module provides access to the
1646{\em Panel Library}
Guido van Rossumd38b7641991-01-25 13:26:13 +00001647built by NASA Ames (to get it, send e-mail to
1648{\tt panel-request@nas.nasa.gov}).
Guido van Rossum515834a1991-01-22 11:45:29 +00001649All access to it should be done through the standard module
1650{\tt panel},
1651which transparantly exports most functions from
1652{\tt pnl}
1653but redefines
1654{\tt pnl.dopanel()}.
1655
1656{\bf Warning:}
1657the {\Python} interpreter will dump core if you don't create a GL window
1658before calling
1659{\tt pnl.mkpanel()}.
1660
1661The module is too large to document here in its entirety.
1662
1663\section{Standard Modules}
1664
1665The following standard modules are defined.
1666They are available in one of the directories in the default module
1667search path (try printing
1668{\tt sys.path}
1669to find out the default search path.)
1670
1671\subsection{Standard Module {\tt string}}
1672
1673This module defines some constants useful for checking character
1674classes, some exceptions, and some useful string functions.
1675The constants are:
1676\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001677\funcitem{digits}
Guido van Rossum515834a1991-01-22 11:45:29 +00001678The string
1679{\tt '0123456789'}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001680\funcitem{hexdigits}
Guido van Rossum515834a1991-01-22 11:45:29 +00001681The string
1682{\tt '0123456789abcdefABCDEF'}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001683\funcitem{letters}
Guido van Rossum515834a1991-01-22 11:45:29 +00001684The concatenation of the strings
1685{\tt lowercase}
1686and
1687{\tt uppercase}
1688described below.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001689\funcitem{lowercase}
Guido van Rossum515834a1991-01-22 11:45:29 +00001690The string
1691{\tt 'abcdefghijklmnopqrstuvwxyz'}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001692\funcitem{octdigits}
Guido van Rossum515834a1991-01-22 11:45:29 +00001693The string
1694{\tt '01234567'}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001695\funcitem{uppercase}
Guido van Rossum515834a1991-01-22 11:45:29 +00001696The string
1697{\tt 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001698\funcitem{whitespace}
Guido van Rossum515834a1991-01-22 11:45:29 +00001699A string containing all characters that are considered whitespace,
1700i.e.,
1701space, tab and newline.
1702This definition is used by
1703{\tt split()}
1704and
1705{\tt strip()}.
1706\end{description}
1707
1708The exceptions are:
1709\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001710\excitem{atoi\_error}{non-numeric argument to string.atoi}
Guido van Rossum515834a1991-01-22 11:45:29 +00001711%.br
1712Exception raised by
1713{\tt atoi}
1714when a non-numeric string argument is detected.
1715The exception argument is the offending string.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001716\excitem{index\_error}{substring not found in string.index}
Guido van Rossum515834a1991-01-22 11:45:29 +00001717%.br
1718Exception raised by
1719{\tt index}
1720when
1721{\tt sub}
1722is not found.
1723The argument are the offending arguments to index: {\tt (s, sub)}.
1724\end{description}
1725
1726The functions are:
1727\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001728\funcitem{atoi}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +00001729Converts a string to a number.
1730The string must consist of one or more digits, optionally preceded by a
1731sign ({\tt '+'} or {\tt '-'}).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001732\funcitem{index}{s, sub}
Guido van Rossum515834a1991-01-22 11:45:29 +00001733Returns the lowest index in
1734{\tt s}
1735where the substring
1736{\tt sub}
1737is found.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001738\funcitem{lower}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +00001739Convert letters to lower case.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001740\funcitem{split}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +00001741Returns a list of the whitespace-delimited words of the string
1742{\tt s}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001743\funcitem{splitfields}{s, sep}
Guido van Rossum515834a1991-01-22 11:45:29 +00001744%.br
1745Returns a list containing the fields of the string
1746{\tt s},
1747using the string
1748{\tt sep}
1749as a separator.
1750The list will have one more items than the number of non-overlapping
1751occurrences of the separator in the string.
1752Thus,
1753{\tt string.splitfields(s, ' ')}
1754is not the same as
1755{\tt string.split(s)},
1756as the latter only returns non-empty words.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001757\funcitem{strip}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +00001758Removes leading and trailing whitespace from the string
1759{\tt s}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001760\funcitem{swapcase}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +00001761Converts lower case letters to upper case and vice versa.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001762\funcitem{upper}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +00001763Convert letters to upper case.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001764\funcitem{ljust(s, width), rjust(s, width), center}{s, width}
Guido van Rossum515834a1991-01-22 11:45:29 +00001765%.br
1766These functions respectively left-justify, right-justify and center a
1767string in a field of given width.
1768They return a string that is at least
1769{\tt width}
1770characters wide, created by padding the string
1771{\tt s}
1772with spaces until the given width on the right, left or both sides.
1773The string is never truncated.
1774\end{description}
1775
1776\subsection{Standard Module {\tt path}}
1777
1778This module implements some useful functions on POSIX pathnames.
1779\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001780\funcitem{basename}{p}
Guido van Rossum515834a1991-01-22 11:45:29 +00001781Returns the base name of pathname
1782{\tt p}.
1783This is the second half of the pair returned by
1784{\tt path.split(p)}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001785\funcitem{cat}{p, q}
Guido van Rossum515834a1991-01-22 11:45:29 +00001786Performs intelligent pathname concatenation on paths
1787{\tt p}
1788and
1789{\tt q}:
1790If
1791{\tt q}
1792is an absolute path, the return value is
1793{\tt q}.
1794Otherwise, the concatenation of
1795{\tt p}
1796and
1797{\tt q}
1798is returned, with a slash ({\tt '/'}) inserted unless
1799{\tt p}
1800is empty or ends in a slash.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001801\funcitem{commonprefix}{list}
Guido van Rossum515834a1991-01-22 11:45:29 +00001802%.br
1803Returns the longest string that is a prefix of all strings in
1804{\tt list}.
1805If
1806{\tt list}
1807is empty, the empty string ({\tt ''}) is returned.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001808\funcitem{exists}{p}
Guido van Rossum515834a1991-01-22 11:45:29 +00001809Returns true if
1810{\tt p}
1811refers to an existing path.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001812\funcitem{isdir}{p}
Guido van Rossum515834a1991-01-22 11:45:29 +00001813Returns true if
1814{\tt p}
1815refers to an existing directory.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001816\funcitem{islink}{p}
Guido van Rossum515834a1991-01-22 11:45:29 +00001817Returns true if
1818{\tt p}
1819refers to a directory entry that is a symbolic link.
1820Always false if symbolic links are not supported.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001821\funcitem{ismount}{p}
Guido van Rossum515834a1991-01-22 11:45:29 +00001822Returns true if
1823{\tt p}
1824is an absolute path that occurs in the mount table as output by the
1825{\tt /etc/mount}
1826utility.
1827This output is read once when the function is used for the first
1828time.%
1829\footnote{
1830Is there a better way to check for mount points?
1831}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001832\funcitem{split}{p}
Guido van Rossum515834a1991-01-22 11:45:29 +00001833Returns a pair
1834{\tt (head,~tail)}
1835such that
1836{\tt tail}
1837contains no slashes and
1838{\tt path.cat(head, tail)}
1839is equal to
1840{\tt p}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001841\funcitem{walk}{p, visit, arg}
Guido van Rossum515834a1991-01-22 11:45:29 +00001842%.br
1843Calls the function
1844{\tt visit}
1845with arguments
1846{\tt (arg, dirname, names)}
1847for each directory in the directory tree rooted at
1848{\tt p}
1849(including
1850{\tt p}
1851itself, if it is a directory).
1852The argument
1853{\tt dirname}
1854specifies the visited directory, the argument
1855{\tt names}
1856lists the files in the directory (gotten from
1857{\tt posix.listdir(dirname)}).
1858The
1859{\tt visit}
1860function may modify
1861{\tt names}
1862to influence the set of directories visited below
1863{\tt dirname},
1864e.g.,
1865to avoid visiting certain parts of the tree.
1866(The object referred to by
1867{\tt names}
1868must be modified in place, using
1869{\tt del}
1870or slice assignment.)
1871\end{description}
1872
1873\subsection{Standard Module {\tt getopt}}
1874
1875This module helps scripts to parse the command line arguments in
1876{\tt sys.argv}.
1877It uses the same conventions as the {\UNIX}
1878{\tt getopt()}
1879function.
1880It defines the function
1881{\tt getopt.getopt(args, options)}
1882and the exception
1883{\tt getopt.error}.
1884
1885The first argument to
1886{\tt getopt()}
1887is the argument list passed to the script with its first element
1888chopped off (i.e.,
1889{\tt sys.argv[1:]}).
1890The second argument is the string of option letters that the
1891script wants to recognize, with options that require an argument
1892followed by a colon (i.e., the same format that {\UNIX}
1893{\tt getopt()}
1894uses).
1895The return value consists of two elements: the first is a list of
1896option-and-value pairs; the second is the list of program arguments
1897left after the option list was stripped (this is a trailing slice of the
1898first argument).
1899Each option-and-value pair returned has the option as its first element,
1900prefixed with a hyphen (e.g.,
1901{\tt '-x'}),
1902and the option argument as its second element, or an empty string if the
1903option has no argument.
1904The options occur in the list in the same order in which they were
1905found, thus allowing multiple occurrences.
1906Example:
Guido van Rossumd38b7641991-01-25 13:26:13 +00001907\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001908>>> import getopt, string
1909>>> args = string.split('-a -b -cfoo -d bar a1 a2')
1910>>> args
1911['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2']
1912>>> optlist, args = getopt.getopt(args, 'abc:d:')
1913>>> optlist
1914[('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')]
1915>>> args
1916['a1', 'a2']
1917>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +00001918\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001919The exception
1920{\tt getopt.error = 'getopt error'}
1921is raised when an unrecognized option is found in the argument list or
1922when an option requiring an argument is given none.
1923The argument to the exception is a string indicating the cause of the
1924error.
1925
1926\subsection{Standard Module {\tt rand}}
1927
1928This module implements a pseudo-random number generator similar to
1929{\tt rand()}
1930in C.
1931It defines the following functions:
1932\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001933\funcitem{rand}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001934Returns an integer random number in the range [0 ... 32768).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001935\funcitem{choice}{s}
Guido van Rossum515834a1991-01-22 11:45:29 +00001936Returns a random element from the sequence (string, tuple or list)
1937{\tt s.}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001938\funcitem{srand}{seed}
Guido van Rossum515834a1991-01-22 11:45:29 +00001939Initializes the random number generator with the given integral seed.
1940When the module is first imported, the random number is initialized with
1941the current time.
1942\end{description}
1943
1944\subsection{Standard Module {\tt whrandom}}
1945
1946This module implements a Wichmann-Hill pseudo-random number generator.
1947It defines the following functions:
1948\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001949\funcitem{random}{}
Guido van Rossum515834a1991-01-22 11:45:29 +00001950Returns the next random floating point number in the range [0.0 ... 1.0).
Guido van Rossum8ec63501991-02-19 12:53:17 +00001951\funcitem{seed}{x, y, z}
Guido van Rossum515834a1991-01-22 11:45:29 +00001952Initializes the random number generator from the integers
1953{\tt x},
1954{\tt y}
1955and
1956{\tt z}.
1957When the module is first imported, the random number is initialized
1958using values derived from the current time.
1959\end{description}
1960
1961\subsection{Standard Module {\tt stdwinevents}}
1962
1963This module defines constants used by STDWIN for event types
1964({\tt WE\_ACTIVATE} etc.), command codes ({\tt WC\_LEFT} etc.)
1965and selection types ({\tt WS\_PRIMARY} etc.).
1966Read the file for details.
1967Suggested usage is
Guido van Rossumd38b7641991-01-25 13:26:13 +00001968\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001969>>> from stdwinevents import *
1970>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +00001971\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001972
1973\subsection{Standard Module {\tt rect}}
1974
1975This module contains useful operations on rectangles.
1976A rectangle is defined as in module
1977{\tt stdwin}:
1978a pair of points, where a point is a pair of integers.
1979For example, the rectangle
Guido van Rossumd38b7641991-01-25 13:26:13 +00001980\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00001981(10, 20), (90, 80)
Guido van Rossumd38b7641991-01-25 13:26:13 +00001982\end{verbatim}\ecode
Guido van Rossum515834a1991-01-22 11:45:29 +00001983is a rectangle whose left, top, right and bottom edges are 10, 20, 90
1984and 80, respectively.
1985Note that the positive vertical axis points down (as in
1986{\tt stdwin}).
1987
1988The module defines the following objects:
1989\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00001990\excitem{error}{rect.error}
Guido van Rossum515834a1991-01-22 11:45:29 +00001991%.br
1992The exception raised by functions in this module when they detect an
1993error.
1994The exception argument is a string describing the problem in more
1995detail.
Guido van Rossum8ec63501991-02-19 12:53:17 +00001996\funcitem{empty}
Guido van Rossum515834a1991-01-22 11:45:29 +00001997%.br
1998The rectangle returned when some operations return an empty result.
1999This makes it possible to quickly check whether a result is empty:
Guido van Rossumd38b7641991-01-25 13:26:13 +00002000\bcode\begin{verbatim}
Guido van Rossum515834a1991-01-22 11:45:29 +00002001>>> import rect
2002>>> r1 = (10, 20), (90, 80)
2003>>> r2 = (0, 0), (10, 20)
2004>>> r3 = rect.intersect(r1, r2)
2005>>> if r3 is rect.empty: print 'Empty intersection'
2006Empty intersection
2007>>>
Guido van Rossumd38b7641991-01-25 13:26:13 +00002008\end{verbatim}\ecode
Guido van Rossum8ec63501991-02-19 12:53:17 +00002009\funcitem{is\_empty}{r}
Guido van Rossum515834a1991-01-22 11:45:29 +00002010%.br
2011Returns true if the given rectangle is empty.
2012A rectangle
2013{\em (left,~top), (right,~bottom)}
2014is empty if
2015{\em left~$\geq$~right}
2016or
2017{\em top~$\leq$~bottom}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00002018\funcitem{intersect}{list}
Guido van Rossum515834a1991-01-22 11:45:29 +00002019%.br
2020Returns the intersection of all rectangles in the list argument.
2021It may also be called with a tuple argument or with two or more
2022rectangles as arguments.
2023Raises
2024{\tt rect.error}
2025if the list is empty.
2026Returns
2027{\tt rect.empty}
2028if the intersection of the rectangles is empty.
Guido van Rossum8ec63501991-02-19 12:53:17 +00002029\funcitem{union}{list}
Guido van Rossum515834a1991-01-22 11:45:29 +00002030%.br
2031Returns the smallest rectangle that contains all non-empty rectangles in
2032the list argument.
2033It may also be called with a tuple argument or with two or more
2034rectangles as arguments.
2035Returns
2036{\tt rect.empty}
2037if the list is empty or all its rectangles are empty.
Guido van Rossum8ec63501991-02-19 12:53:17 +00002038\funcitem{pointinrect}{point, rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00002039%.br
2040Returns true if the point is inside the rectangle.
2041By definition, a point
2042{\em (h,~v)}
2043is inside a rectangle
2044{\em (left,~top),}
2045{\em (right,~bottom)}
2046if
2047{\em left~$\leq$~h~$<$~right}
2048and
2049{\em top~$\leq$~v~$<$~bottom}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00002050\funcitem{inset(rect, }{dh, dv)}
Guido van Rossum515834a1991-01-22 11:45:29 +00002051%.br
2052Returns a rectangle that lies inside the
2053{\tt rect}
2054argument by
2055{\tt dh}
2056pixels horizontally
2057and
2058{\tt dv}
2059pixels
2060vertically.
2061If
2062{\tt dh}
2063or
2064{\tt dv}
2065is negative, the result lies outside
2066{\tt rect}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00002067\funcitem{rect2geom}{rect}
Guido van Rossum515834a1991-01-22 11:45:29 +00002068%.br
2069Converts a rectangle to geometry representation:
2070{\em (left,~top),}
2071{\em (width,~height)}.
Guido van Rossum8ec63501991-02-19 12:53:17 +00002072\funcitem{geom2rect}{geom}
Guido van Rossum515834a1991-01-22 11:45:29 +00002073%.br
2074Converts a rectangle given in geometry representation back to the
2075standard rectangle representation
2076{\em (left,~top),}
2077{\em (right,~bottom)}.
2078\end{description}
2079
2080\subsection{Standard Modules {\tt GL} and {\tt DEVICE}}
2081
2082These modules define the constants used by the Silicon Graphics
2083{\em Graphics Library}
2084that C programmers find in the header files
2085{\tt <gl/gl.h>}
2086and
2087{\tt <gl/device.h>}.
2088Read the module files for details.
2089
2090\subsection{Standard Module {\tt panel}}
2091
2092This module should be used instead of the built-in module
2093{\tt pnl}
2094to interface with the
2095{\em Panel Library}.
2096
2097The module is too large to document here in its entirety.
2098One interesting function:
2099\begin{description}
Guido van Rossum8ec63501991-02-19 12:53:17 +00002100\funcitem{defpanellist}{filename}
Guido van Rossum515834a1991-01-22 11:45:29 +00002101%.br
2102Parses a panel description file containing S-expressions written by the
2103{\em Panel Editor}
2104that accompanies the Panel Library and creates the described panels.
2105It returns a list of panel objects.
2106\end{description}
2107
2108{\bf Warning:}
2109the {\Python} interpreter will dump core if you don't create a GL window
2110before calling
2111{\tt panel.mkpanel()}
2112or
2113{\tt panel.defpanellist()}.
2114
Guido van Rossum0ed69181991-01-24 16:54:15 +00002115\subsection{Standard Module {\tt panelparser}}
Guido van Rossum515834a1991-01-22 11:45:29 +00002116
2117This module defines a self-contained parser for S-expressions as output
2118by the Panel Editor (which is written in Scheme so it can't help writing
2119S-expressions).
2120The relevant function is
Guido van Rossum0ed69181991-01-24 16:54:15 +00002121{\tt panelparser.parse\_file(file)}
Guido van Rossum515834a1991-01-22 11:45:29 +00002122which has a file object (not a filename!) as argument and returns a list
2123of parsed S-expressions.
2124Each S-expression is converted into a {\Python} list, with atoms converted
2125to {\Python} strings and sub-expressions (recursively) to {\Python} lists.
2126For more details, read the module file.
2127
Guido van Rossum8ec63501991-02-19 12:53:17 +00002128\section{P.M.}
Guido van Rossum515834a1991-01-22 11:45:29 +00002129
2130\begin{verse}
Guido van Rossum8ec63501991-02-19 12:53:17 +00002131
Guido van Rossum515834a1991-01-22 11:45:29 +00002132commands
2133
2134cmp?
2135
2136*cache?
2137
2138localtime?
2139
2140calendar?
2141
2142\_\_dict?
Guido van Rossum8ec63501991-02-19 12:53:17 +00002143
2144mac?
2145
Guido van Rossum515834a1991-01-22 11:45:29 +00002146\end{verse}
2147
2148\end{document}