blob: 43866d1fe4d3f0bb5fe72c2c88e32e661af475e5 [file] [log] [blame]
Guido van Rossuma7925f11994-01-26 10:20:16 +00001Subject: FAQ: Python -- an object-oriented language
Guido van Rossum5333c5d1994-04-11 11:06:22 +00002Newsgroups: comp.lang.python,comp.answers,news.answers
3Followup-to: comp.lang.python
Guido van Rossuma7925f11994-01-26 10:20:16 +00004From: guido@cwi.nl (Guido van Rossum)
5Reply-to: guido@cwi.nl (Guido van Rossum)
6Approved: news-answers-request@MIT.Edu
7
8Archive-name: python-faq/part1
Guido van Rossumf8c76d01994-08-17 12:19:53 +00009Version: 1.12
Guido van Rossum3de27361994-07-25 14:19:33 +000010Last-modified: 25 July 1994
Guido van Rossuma7925f11994-01-26 10:20:16 +000011
12This article contains answers to Frequently Asked Questions about
13Python (an object-oriented interpreted programming language -- see
14the answer to question 1.1 for a short overview).
15
16Copyright 1993, 1994 Guido van Rossum. Unchanged electronic
17redistribution of this FAQ is allowed. Printed redistribution only
18with permission of the author. No warranties.
19
20Author's address:
21 Guido van Rossum
22 CWI, dept. CST
23 Kruislaan 413
24 P.O. Box 94079
25 1090 GB Amsterdam
26 The Netherlands
27Email: guido@cwi.nl
28
29The latest version of this FAQ is available by anonymous ftp from
Guido van Rossum7ce61c11994-06-13 15:13:56 +000030ftp.cwi.nl [192.16.191.128] in the directory /pub/python, with
Guido van Rossuma7925f11994-01-26 10:20:16 +000031filename python-FAQ. It will also be posted regularly to the
Guido van Rossum5333c5d1994-04-11 11:06:22 +000032newsgroups comp.answers and comp.lang.python.
Guido van Rossuma7925f11994-01-26 10:20:16 +000033
34Many FAQs, including this one, are available by anonymous ftp from
Guido van Rossumea2c6f71994-07-14 12:35:14 +000035rtfm.mit.edu [18.181.0.24] in the directory pub/usenet/news.answers.
Guido van Rossuma7925f11994-01-26 10:20:16 +000036The name under which a FAQ is archived appears in the Archive-name line
37at the top of the article. This FAQ is archived as python-faq/part1.
38
39There's a mail server on that machine which will send you files from
40the archive by e-mail if you have no ftp access. You send a e-mail
41message to mail-server@rtfm.mit.edu containing the single word help in
42the message body to receive instructions.
43
44This FAQ is divided in the following chapters:
45
46 1. General information and availability
47 2. Python in the real world
48 3. Building Python
49 4. Programming in Python
50 5. Extending Python
51 6. Python's design
52 7. Using Python on non-UNIX platforms
53
54To find the start of a particular chapter, search for the chapter number
55followed by a dot and a space at the beginning of a line (e.g. to
56find chapter 4 in vi, type /^4\. /).
57
58Here's an overview of the questions per chapter:
59
60 1. General information and availability
61 1.1. Q. What is Python?
62 1.2. Q. Why is it called Python?
63 1.3. Q. How do I obtain a copy of the Python source?
64 1.4. Q. How do I get documentation on Python?
Guido van Rossumc50158e1994-05-31 09:18:50 +000065 1.5. Q. Are there other ftp sites that mirror the Python distribution?
66 1.6. Q. Is there a newsgroup or mailing list devoted to Python?
67 1.7. Q. Is there a book on Python, or will there be one out soon?
68 1.8. Q. Are there any published articles about Python that I can quote?
69 1.9. Q. How does the Python version numbering scheme work?
70 1.10. Q. Are there other ftp sites that carry Python related material?
Guido van Rossum7ce61c11994-06-13 15:13:56 +000071 1.11. Q. Are there copyright restrictions on the use of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +000072
73 2. Python in the real world
74 2.1. Q. How many people are using Python?
75 2.2. Q. Have any significant projects been done in Python?
76 2.3. Q. Are there any commercial projects going on using Python?
Guido van Rossum95f61a71994-01-26 17:23:37 +000077 2.4. Q. How stable is Python?
78 2.5. Q. What new developments are expected for Python in the future?
Guido van Rossum3de27361994-07-25 14:19:33 +000079 2.6. Q. Is it reasonable to propose incompatible changes to Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +000080
81 3. Building Python
Guido van Rossum91f60831994-02-15 15:52:27 +000082 3.1. Q. Is there a test set?
83 3.2. Q. When running the test set, I get complaints about floating point
Guido van Rossuma7925f11994-01-26 10:20:16 +000084 operations, but when playing with floating point operations I cannot
85 find anything wrong with them.
Guido van Rossum91f60831994-02-15 15:52:27 +000086 3.3. Q. Link errors building Python with STDWIN on SGI IRIX.
87 3.4. Q. Link errors after rerunning the configure script.
88 3.5. Q. The python interpreter complains about options passed to a
Guido van Rossum24349991994-02-02 14:12:45 +000089 script (after the script name).
Guido van Rossum91f60831994-02-15 15:52:27 +000090 3.6. Q. When building on the SGI, make tries to run python to create
Guido van Rossum5333c5d1994-04-11 11:06:22 +000091 glmodule.c, but python hasn't been built or installed yet.
Guido van Rossum3de27361994-07-25 14:19:33 +000092 3.7. Q. Python built with gcc for the DEC Alpha doesn't work.
93 3.8. Q. Other trouble building Python on platform X.
Guido van Rossuma7925f11994-01-26 10:20:16 +000094
95 4. Programming in Python
Guido van Rossum24349991994-02-02 14:12:45 +000096 4.1. Q. Is there a source code level debugger with breakpoints, step,
97 etc.?
98 4.2. Q. Can I create an object class with some methods implemented in
Guido van Rossuma7925f11994-01-26 10:20:16 +000099 C and others in Python (e.g. through inheritance)? (Also phrased as:
100 Can I use a built-in type as base class?)
Guido van Rossum24349991994-02-02 14:12:45 +0000101 4.3. Q. Is there a curses/termcap package for Python?
102 4.4. Q. Is there an equivalent to C's onexit() in Python?
103 4.5. Q. When I define a function nested inside another function, the
Guido van Rossuma7925f11994-01-26 10:20:16 +0000104 nested function seemingly can't access the local variables of the
105 outer function. What is going on? How do I pass local data to a
106 nested function?
Guido van Rossum24349991994-02-02 14:12:45 +0000107 4.6. Q. How do I iterate over a sequence in reverse order?
108 4.7. Q. My program is too slow. How do I speed it up?
109 4.8. Q. When I have imported a module, then edit it, and import it
Guido van Rossuma7925f11994-01-26 10:20:16 +0000110 again (into the same Python process), the changes don't seem to take
111 place. What is going on?
Guido van Rossum24349991994-02-02 14:12:45 +0000112 4.9. Q. I have a module in which I want to execute some extra code when it
113 is run as a script. How do I find out whether I am running as a
114 script?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000115 4.10. Q. I try to run a program from the Demo directory but it fails with
116 ImportError: No module named ...; what gives?
117 4.11. Q. What GUI toolkits exist for Python?
118 4.12. Q. Are there any interfaces to commercial database in Python?
Guido van Rossumc24da7c1994-09-23 14:08:41 +0000119 4.13. Q. Is it possible to write obfuscated one-liners in Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000120
121 5. Extending Python
122 5.1. Q. Can I create my own functions in C?
123 5.2. Q. Can I create my own functions in C++?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000124 5.3. Q. How can I execute arbitrary Python statements from C?
125 5.4. Q. How can I evaluate an arbitrary Python expression from C?
126 5.5. Q. How do I extract C values from a Python object?
127 5.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000128
129 6. Python's design
130 6.1. Q. Why isn't there a generic copying operation for objects in
131 Python?
132 6.2. Q. Why isn't there a generic way to implement persistent objects
133 in Python? (Persistent == automatically saved to and restored from
134 disk.)
135 6.3. Q. Why isn't there a switch or case statement in Python?
Guido van Rossumc50158e1994-05-31 09:18:50 +0000136 6.4. Q. Why does Python use indentation for grouping of statements?
Guido van Rossum3de27361994-07-25 14:19:33 +0000137 6.5. Q. Why are Python strings immutable?
138 6.6. Q. Why don't strings have methods like index() or sort(), like
139 lists?
140 6.7. Q. Why does Python use methods for some functionality
141 (e.g. list.index()) but functions for other (e.g. len(list))?
142 6.8. Q. Why can't I derive a class from built-in types (e.g. lists or
143 files)?
144 6.9. Q. Why must 'self' be declared and used explicitly in method
145 definitions and calls?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000146
147 7. Using Python on non-UNIX platforms
Guido van Rossum91f60831994-02-15 15:52:27 +0000148 7.1. Q. Is there a Mac version of Python?
149 7.2. Q. Is there a DOS version of Python?
150 7.3. Q. Is there a Windows version of Python?
151 7.4. Q. Is there a Windows NT version of Python?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000152 7.5. Q. Is there an OS/2 version of Python?
153 7.6. Q. I have the PC version but it appears to be only a binary.
154 Where's the library?
155 7.7. Q. Where's the documentation for the Mac or PC version?
156 7.8. Q. The Mac (PC) version doesn't seem to have any facilities for
Guido van Rossum91f60831994-02-15 15:52:27 +0000157 creating or editing programs apart from entering it interactively, and
158 there seems to be no way to save code that was entered interactively.
159 How do I create a Python program on the Mac (PC)?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000160
161To find a particular question, search for the question number followed
162by a dot, a space, and a Q at the beginning of a line (e.g. to find
163question 4.2 in vi, type /^4\.2\. Q/).
164
165
1661. General information and availability
167=======================================
168
1691.1. Q. What is Python?
170
171A. Python is an interpreted, interactive, object-oriented programming
172language. It incorporates modules, exceptions, dynamic typing, very
173high level dynamic data types, and classes. Python combines
174remarkable power with very clear syntax. It has interfaces to many
175system calls and libraries, as well as to various window systems, and
176is extensible in C or C++. It is also usable as an extension language
177for applications that need a programmable interface. Finally, Python
178is portable: it runs on many brands of UNIX, on the Mac, and on
179MS-DOS.
180
181To find out more, the best thing to do is to start reading the
182tutorial from the documentation set (see a few questions further
183down).
184
1851.2. Q. Why is it called Python?
186
187A. Apart from being a computer wizard, I'm also a fan of "Monty
188Python's Flying Circus" (a BBC comedy series from the seventies, in
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000189the -- unlikely -- case you didn't know). It occurred to me one day
190that I needed a name that was short, unique, and slightly mysterious.
191And I happened to be reading some scripts from the series at the
192time... So then I decided to call my language Python. But Python is
193not a joke. And don't you associate it with dangerous reptiles
194either!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000195
1961.3. Q. How do I obtain a copy of the Python source?
197
198A. The latest Python source distribution is always available by
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000199anonymous ftp from ftp.cwi.nl [192.16.191.128] in the directory
Guido van Rossum44b4cb11994-05-04 13:28:51 +0000200/pub/python, with filename python<version>.tar.gz. (Old versions may
201have an extension of .Z, indicating use of "compress" compression.)
202It is a gzip'ed tar file containing the complete C source, LaTeX
203documentation, Python library modules, example programs, and several
204useful pieces of freely distributable software. This will compile and
Guido van Rossum3de27361994-07-25 14:19:33 +0000205run out of the box on most UNIX platforms. (See section 7 for
206non-UNIX information.)
Guido van Rossuma7925f11994-01-26 10:20:16 +0000207
2081.4. Q. How do I get documentation on Python?
209
210A. The latest Python documentation set is always available by
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000211anonymous ftp from ftp.cwi.nl [192.16.191.128] in the directory
Guido van Rossum44b4cb11994-05-04 13:28:51 +0000212/pub/python, with filename pythondoc-ps<version>.tar.gz. It is a
213gzip'ed tar file containing PostScript files of the reference manual,
Guido van Rossum3de27361994-07-25 14:19:33 +0000214the library manual, and the tutorial. Note that the library manual is
215the most important one of the set, as much of Python's power stems
216from the standard or built-in types, functions and modules, all of
217which are described here. PostScript for a high-level description of
218Python is in the file nluug-paper.ps.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000219
Guido van Rossumc50158e1994-05-31 09:18:50 +00002201.5. Q. Are there other ftp sites that mirror the Python distribution?
221
222A. The following sites keep mirrors of the Python distribution:
Guido van Rossuma7925f11994-01-26 10:20:16 +0000223
224Site IP address Directory
225
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000226gatekeeper.dec.com 16.1.0.2 /pub/plan/python
Guido van Rossuma7925f11994-01-26 10:20:16 +0000227ftp.uu.net 192.48.96.9 /languages/python
228ftp.wustl.edu 128.252.135.4 /graphics/graphics/sgi-stuff/python
Guido van Rossumc50158e1994-05-31 09:18:50 +0000229ftp.funet.fi 128.214.6.100 /pub/languages/python
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000230ftp.fu-berlin.de 130.133.1.18 /unix/languages/python (*python* only)
Guido van Rossumc50158e1994-05-31 09:18:50 +0000231ftp.sunet.se 130.238.127.3 /pub/lang/python
Guido van Rossumea2c6f71994-07-14 12:35:14 +0000232unix.hensa.ac.uk 129.12.43.16 /uunet/languages/python
Guido van Rossuma7925f11994-01-26 10:20:16 +0000233
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000234Or try archie on e.g. python1.0 to locate the nearest copy of that
235version...
Guido van Rossuma7925f11994-01-26 10:20:16 +0000236
Guido van Rossumc50158e1994-05-31 09:18:50 +00002371.6. Q. Is there a newsgroup or mailing list devoted to Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000238
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000239A. There is a newsgroup, comp.lang.python, and a mailing list. The
240newsgroup and mailing list are gatewayed into each other -- if you can
241read news it is not necessary to subscribe to the mailing list. Send
242e-mail to python-list-request@cwi.nl to (un)subscribe to the mailing
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000243list. Once you're on, send e-mail tp python-list@cwi.nl to send mail
244to the entire mailing list and newsgroup.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000245
Guido van Rossumc50158e1994-05-31 09:18:50 +00002461.7. Q. Is there a book on Python, or will there be one out soon?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000247
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000248A. Unfortunately, not yet. Mark Lutz and I are planning to write one,
249but we are still a in very preliminary stage. If you would like to
250beat us at it and get rich from book royalties, go ahead!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000251
Guido van Rossumc50158e1994-05-31 09:18:50 +00002521.8. Q. Are there any published articles about Python that I can quote?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000253
254A. So far the only refereed and published article that describes
255Python in some detail is:
256
257 Guido van Rossum and Jelke de Boer, "Interactively Testing Remote
258 Servers Using the Python Programming Language", CWI Quarterly, Volume
259 4, Issue 4 (December 1991), Amsterdam, pp 283-303.
260
261LaTeX source for this paper is available as part of the Python source
262distribution.
263
264A more recent high-level description of Python is:
265
266 Guido van Rossum, "An Introduction to Python for UNIX/C
267 Programmers", in the proceedings of the NLUUG najaarsconferentie
268 1993 (dutch UNIX users group meeting november 1993).
269
270PostScript for this paper and for the slides used for the accompanying
271presentation can be found in the ftp directory mentioned a few
272questions earlier, with filenames nluug-paper.ps and nluug-slides.ps,
273respectively.
274
Guido van Rossumc50158e1994-05-31 09:18:50 +00002751.9. Q. How does the Python version numbering scheme work?
Guido van Rossum95f61a71994-01-26 17:23:37 +0000276
277A. Python versions are numbered A.B.C. A is the major version number
278-- it is only incremented for major changes in functionality or source
279structure. B is the minor version number, incremented for less
280earth-shattering changes to a release. C is the patchlevel -- it is
281incremented for each new release. Note that in the past, patches have
282added significant changes; in fact the changeover from 0.9.9 to 1.0.0
283was the first time that either A or B changed!
284
Guido van Rossumc50158e1994-05-31 09:18:50 +00002851.10. Q. Are there other ftp sites that carry Python related material?
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000286
287A. An interesting ftp site for Python users is ftp.markv.com
288(192.122.251.1); the directory pub/python contains a growing
289collection of interesting Python scripts. To submit a script for
290inclusion, place it together with a readme file (with extension
291.readme) in the publicly writable directory /incoming/python. This
292service is maintained by Lance Ellinghouse <lance@markv.com>.
293
Guido van Rossum7ce61c11994-06-13 15:13:56 +00002941.11. Q. Are there copyright restrictions on the use of Python?
295
296A. Hardly. You can do anything you want with the source, as long as
297you leave the copyrights in, display those copyrights in any
298documentation about Python that you produce, don't use the author's
299institute's name in publicity without prior written permission, and
300don't hold them responsible for anything (read the actual copyright
301for a precise legal wording).
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000302
Guido van Rossuma7925f11994-01-26 10:20:16 +0000303
3042. Python in the real world
305===========================
306
3072.1. Q. How many people are using Python?
308
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000309A. I don't know, but the maximum number of simultaneous subscriptions
310to the Python mailing list before it was gatewayed into the newsgroup
311was about 180 (several of which were local redistribution lists). I
312believe that many active Python users don't bother to subscribe to the
313list, and now that there's a newsgroup the mailing list subscription
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000314is even less meaningful. I see new names on the newsgroup all the
315time and my best guess is that there are currently at least several
316thousands of users.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000317
3182.2. Q. Have any significant projects been done in Python?
319
320A. Here at CWI (the home of Python), we have written a 20,000 line
321authoring environment for transportable hypermedia presentations, a
Guido van Rossum5333c5d1994-04-11 11:06:22 +00003225,000 line multimedia teleconferencing tool, as well as many many
323smaller programs.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000324
325The University of Virginia uses Python to control a virtual reality
326engine. Contact: Matt Conway <conway@virginia.edu>.
327
328See also the next question.
329
3302.3. Q. Are there any commercial projects going on using Python?
331
332A. Several companies have revealed to me that they are planning or
333considering to use Python in a future product. The furthest is
334Sunrise Software, who already have a product out using Python -- they
335use Python for a GUI management application and an SNMP network
336manangement application. Contact: <info@sunrise.com>.
337
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000338Infoseek is using python to implement their commercial WWW information
339retrieval service. Contact: <info@infoseek.com>.
340
Guido van Rossuma7925f11994-01-26 10:20:16 +0000341Individuals at many other companies are using Python for
342internal development (witness their contributions to the Python
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000343mailing list or newsgroup).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000344
345Python has also been elected as an extension language by MADE, a
346consortium supported by the European Committee's ESPRIT program and
347consisting of Bull, CWI and some other European companies. Contact:
348Ivan Herman <ivan@cwi.nl>.
349
Guido van Rossum95f61a71994-01-26 17:23:37 +00003502.4. Q. How stable is Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000351
Guido van Rossum3de27361994-07-25 14:19:33 +0000352A. Very stable. While the current version number would suggest it is
353in the early stages of development, in fact new, stable releases
354(numbered 0.9.x and 1.0.x) have been coming out roughly every 3 to 6
Guido van Rossum95f61a71994-01-26 17:23:37 +0000355months for the past four years.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000356
Guido van Rossum95f61a71994-01-26 17:23:37 +00003572.5. Q. What new developments are expected for Python in the future?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000358
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000359A. A proposal is being worked out to change the semantics of operator
360overloading (__add__, __mul__ etc.) to make them more useful for
361implementing types that don't resemble numbers. Additions will be
362__call__ (to call an instance as if it were a function) and __eq__,
363_lt__ etc. (to override individual comparisons). A (new) pthreads
364interface has been submitted which will be integrated in the next
365release. The X11/Motif interface will be improved. There are ideas
366about built-in help using strings placed into function objects, and
367possibly a switch statement.
368
369There will be better ports to the Mac, DOS, Windows, Windows NT, and
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000370OS/2. The Windows ports will support dynamically loaded modules using
371DLLs. There may be a Windows version of STDWIN (someone has actually
372written one and contributed it but it's not robust enough at the
373moment).
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000374
375Also planned is improved support for embedding Python in other
376applications, e.g. by renaming most global symbols to have a "Py"
377prefix and providing more documentation and threading support.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000378
Guido van Rossum3de27361994-07-25 14:19:33 +00003792.6. Q. Is it reasonable to propose incompatible changes to Python?
380
381A. In general, no. There are already millions of lines of Python code
382around the world, so any changes in the language that invalidates more
383than a very small fraction of existing programs has to be frowned
384upon. Even if you can provide a conversion program, there still is
385the problem of updating all documentation. Providing a gradual
386upgrade path is the only way if a feature has to be changed.
387
Guido van Rossuma7925f11994-01-26 10:20:16 +0000388
3893. Building Python
390==================
391
Guido van Rossum91f60831994-02-15 15:52:27 +00003923.1. Q. Is there a test set?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000393
394A. Yes, simply do "import testall" (or "import autotest" if you aren't
395interested in the output). The standard modules whose name begins
396with "test" together comprise the test. The test set doesn't test
397*all* features of Python but it goes a long way to confirm that a new
398port is actually working. The Makefile contains an entry "make test"
399which runs the autotest module.
400
Guido van Rossum91f60831994-02-15 15:52:27 +00004013.2. Q. When running the test set, I get complaints about floating point
Guido van Rossuma7925f11994-01-26 10:20:16 +0000402operations, but when playing with floating point operations I cannot
403find anything wrong with them.
404
405A. The test set makes occasional unwarranted assumptions about the
406semantics of C floating point operations. Until someone donates a
407better floating point test set, you will have to comment out the
408offending floating point tests and execute similar tests manually.
409
Guido van Rossum91f60831994-02-15 15:52:27 +00004103.3. Q. Link errors building Python with STDWIN on SGI IRIX.
Guido van Rossum24349991994-02-02 14:12:45 +0000411
412A. Rebuild STDWIN, specifying "CC=cc -cckr" in the Makefile.
413
Guido van Rossum91f60831994-02-15 15:52:27 +00004143.4. Q. Link errors after rerunning the configure script.
Guido van Rossum24349991994-02-02 14:12:45 +0000415
416A. It is generally necessary to run "make clean" after a configuration
417change.
418
Guido van Rossum91f60831994-02-15 15:52:27 +00004193.5. Q. The python interpreter complains about options passed to a
Guido van Rossum24349991994-02-02 14:12:45 +0000420script (after the script name).
421
422A. You are probably linking with GNU getopt, e.g. through -liberty.
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000423Don't. The reason for the complaint is that GNU getopt, unlike System
424V getopt and other getopt implementations, doesn't consider a
425non-option to be the end of the option list. A quick (and compatible)
426fix for scripts is to add "--" to the interpreter, like this:
427
428 #! /usr/local/bin/python --
429
430You can also use this interactively:
431
432 python -- script.py [options]
Guido van Rossum24349991994-02-02 14:12:45 +0000433
Guido van Rossum91f60831994-02-15 15:52:27 +00004343.6. Q. When building on the SGI, make tries to run python to create
Guido van Rossum24349991994-02-02 14:12:45 +0000435glmodule.c, but python hasn't been built or installed yet.
436
437A. Comment out the line mentioning glmodule.c in Setup and build a
438python without gl first; install it or make sure it is in your $PATH,
439then edit the Setup file again to turn on the gl module, and make
440again. You don't need to do "make clean"; you do need to run "make
441Makefile" in the Modules subdirectory (or just run "make" at the
442toplevel).
443
Guido van Rossum3de27361994-07-25 14:19:33 +00004443.7. Q. Python built with gcc for the DEC Alpha doesn't work.
445
446People have reported problems with both gcc 2.5.8 and 2.6.0. The DEC
447OSF/1 cc compiler does not have these problems so it's probably gcc's
448fault. One person reported that the problem went away when using -g
449instead of -O so this may be an option if you insist on using gcc. If
450someone tracks it down more completely I'd like to hear about it!
451
4523.8. Q. Other trouble building Python on platform X.
Guido van Rossum95f61a71994-01-26 17:23:37 +0000453
454A. Please email the details to <guido@cwi.nl> and I'll look into it.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000455
456
4574. Programming in Python
458========================
459
Guido van Rossum24349991994-02-02 14:12:45 +00004604.1. Q. Is there a source code level debugger with breakpoints, step,
461etc.?
462
463A. Yes. Check out module pdb; pdb.help() prints the documentation (or
464you can read it as Lib/pdb.doc). If you use the STDWIN option,
465there's also a windowing interface, wdb. You can write your own
466debugger by using the code for pdb or wdb as an example.
467
4684.2. Q. Can I create an object class with some methods implemented in
Guido van Rossuma7925f11994-01-26 10:20:16 +0000469C and others in Python (e.g. through inheritance)? (Also phrased as:
470Can I use a built-in type as base class?)
471
472A. No, but you can easily create a Python class which serves as a
473wrapper around a built-in object, e.g. (for dictionaries):
474
475 # A user-defined class behaving almost identical
476 # to a built-in dictionary.
477 class UserDict:
478 def __init__(self): self.data = {}
479 def __repr__(self): return repr(self.data)
480 def __cmp__(self, dict):
481 if type(dict) == type(self.data):
482 return cmp(self.data, dict)
483 else:
484 return cmp(self.data, dict.data)
485 def __len__(self): return len(self.data)
486 def __getitem__(self, key): return self.data[key]
487 def __setitem__(self, key, item): self.data[key] = item
488 def __delitem__(self, key): del self.data[key]
489 def keys(self): return self.data.keys()
490 def items(self): return self.data.items()
491 def values(self): return self.data.values()
492 def has_key(self, key): return self.data.has_key(key)
493
Guido van Rossum24349991994-02-02 14:12:45 +00004944.3. Q. Is there a curses/termcap package for Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000495
496A. No, but you can use the "alfa" (== character cell) version of
497STDWIN. (STDWIN == Standard Windows, a portable windowing system
Guido van Rossum91f60831994-02-15 15:52:27 +0000498interface by the same author, URL: ftp://ftp.cwi.nl/pub/stdwin.)
Guido van Rossuma7925f11994-01-26 10:20:16 +0000499This will also prepare your program for porting to windowing
500environments such as X11 or the Macintosh.
501
Guido van Rossum24349991994-02-02 14:12:45 +00005024.4. Q. Is there an equivalent to C's onexit() in Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000503
504A. Yes, if you import sys and assign a function to sys.exitfunc, it
505will be called when your program exits, is killed by an unhandled
506exception, or (on UNIX) receives a SIGHUP or SIGTERM signal.
507
Guido van Rossum24349991994-02-02 14:12:45 +00005084.5. Q. When I define a function nested inside another function, the
Guido van Rossuma7925f11994-01-26 10:20:16 +0000509nested function seemingly can't access the local variables of the
510outer function. What is going on? How do I pass local data to a
511nested function?
512
513A. Python does not have arbitrarily nested scopes. When you need to
514create a function that needs to access some data which you have
515available locally, create a new class to hold the data and return a
516method of an instance of that class, e.g.:
517
518 class MultiplierClass:
519 def __init__(self, factor):
520 self.factor = factor
521 def multiplier(self, argument):
522 return argument * self.factor
523
524 def generate_multiplier(factor):
525 return MultiplierClass(factor).multiplier
526
527 twice = generate_multiplier(2)
528 print twice(10)
529 # Output: 20
530
Guido van Rossum24349991994-02-02 14:12:45 +00005314.6. Q. How do I iterate over a sequence in reverse order?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000532
533A. If it is a list, the fastest solution is
534
535 list.reverse()
536 try:
537 for x in list:
538 "do something with x"
539 finally:
540 list.reverse()
541
542This has the disadvantage that while you are in the loop, the list
543is temporarily reversed. If you don't like this, you can make a copy.
544This appears expensive but is actually faster than other solutions:
545
546 rev = list[:]
547 rev.reverse()
548 for x in rev:
549 <do something with x>
550
551If it isn't a list, a more general but slower solution is:
552
553 i = len(list)
554 while i > 0:
555 i = i-1
556 x = list[i]
557 <do something with x>
558
559A more elegant solution, is to define a class which acts as a sequence
560and yields the elements in reverse order (solution due to Steve
561Majewski):
562
563 class Rev:
564 def __init__(self, seq):
565 self.forw = seq
566 def __len__(self):
567 return len(self.forw)
568 def __getitem__(self, i):
569 return self.forw[-(i + 1)]
570
571You can now simply write:
572
573 for x in Rev(list):
574 <do something with x>
575
576Unfortunately, this solution is slowest of all, due the the method
577call overhead...
578
Guido van Rossum24349991994-02-02 14:12:45 +00005794.7. Q. My program is too slow. How do I speed it up?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000580
581A. That's a tough one, in general. There are many tricks to speed up
582Python code; I would consider rewriting parts in C only as a last
583resort. One thing to notice is that function and (especially) method
584calls are rather expensive; if you have designed a purely OO interface
585with lots of tiny functions that don't do much more than get or set an
586instance variable or call another method, you may consider using a
587more direct way, e.g. directly accessing instance variables. Also see
588the standard module "profile" (described in the file
589"python/lib/profile.doc") which makes it possible to find out where
590your program is spending most of its time (if you have some patience
591-- the profiling itself can slow your program down by an order of
592magnitude).
593
Guido van Rossum24349991994-02-02 14:12:45 +00005944.8. Q. When I have imported a module, then edit it, and import it
Guido van Rossuma7925f11994-01-26 10:20:16 +0000595again (into the same Python process), the changes don't seem to take
596place. What is going on?
597
598A. For efficiency reasons, Python only reads the module file on the
599first time a module is imported (otherwise a program consisting of
600many modules, each of which imports the same basic module, would read
601the basic module over and over again). To force a changed module
602being read again, do this:
603
604 import modname
605 reload(modname)
606
607Warning: this technique is not 100% fool-proof. In particular,
608modules containing statements like
609
610 from modname import some_objects
611
612will continue to work with the old version of the objects imported
613thus.
614
Guido van Rossum24349991994-02-02 14:12:45 +00006154.9. Q. I have a module in which I want to execute some extra code when it
616is run as a script. How do I find out whether I am running as a
617script?
618
619A. A module can find out its own module name by alooking at the
620(predefined) global variable __name__. If this has the value
621'__main__' you are running as a script. E.g. if you put the following
622on the last line of your module, main() is called only when your
623module is running as a script:
624
625 if __name__ == '__main__': main()
626
Guido van Rossum7ce61c11994-06-13 15:13:56 +00006274.10. Q. I try to run a program from the Demo directory but it fails with
628ImportError: No module named ...; what gives?
629
630A. This is probably an optional module which hasn't been configured on
631your system. This especially happens with modules like "stdwin",
632"gl", "Xt" or "Xm". For stdwin and many other modules, see
633Modules/Setup.in for info on how to add these modules to your Python,
634if it is possible at all. Sometimes you will have to ftp and build
635another package first (e.g. stdwin). Sometimes the module only works
636on specific platforms (e.g. gl only works on SGI machines). For
637X-related modules (Xt and Xm) you will have to do more work: they are
638currently not part of the standard Python distribution. You will have
639to ftp the file "extensions.tar.gz" file from a Python ftp repository
640(e.g. ftp.cwi.nl) and follow the instructions there. Note: the X
641related modules are still somewhat flakey, so don't try this unless
642you know a bit or two about building X applications on your platform.
643
6444.11. Q. What GUI toolkits exist for Python?
645
646A. Depending on what platform(s) you are aiming at, there are several.
647
648- The standard Python distribution comes with an interface to STDWIN,
649a platform-independent low-level windowing interface (you have to ftp
650the source for stdwin separately, e.g. from ftp.cwi.nl in pub/stdwin
651or gatekeeper.dec.com in pub/misc/stdwin). STDWIN runs under X11 or
652the Mac; a Windows port is about to be released.
653
654- For SGI only, there's an interface to the complete GL (Graphics
655Library -- low level but very good 3D capabilities) as well as to
656FORMS (a buttons-and-sliders-etc package built on top of GL by Mark
657Overmars -- ftp'able from ftp.cs.ruu.nl in pub/SGI/FORMS).
658
659- There's an interface to X11, including the Athena and Motif widget
660sets (and a few individual widgets, like Mosaic's HTML widget and
661SGI's GL widget) in the Extensions set, which is separately ftp'able
662from ftp.cwi.nl as pub/python/extensions.tar.gz.
663
664- There's an interface to SUIT, the U of Virginia's Simple User
665Interface Toolkit; it can be ftp'ed from uvacs.cs.virginia.edu as
666pub/suit/python/SUIT_python.tar.Z. A PC binary of Python 1.0.2
667compiled with DJGPP and with SUIT support built-in has been made
668available by Antonio Costa on ftp site asterix.inescn.pt, directory
669pub/PC/python, file pyt102su.exe (a self-extracting archive).
670
671- There's a neat interface to the Tcl/Tk widget set; ftp it from
672ftp.cwi.nl as pub/python/tkinter.tar.gz.
673
674- There's an interface to WAFE, a Tcl interface to the X11 Motif and
675Athena widget sets. Last I heard about it it was included in the
676WAFE 1.0 prerelease, ftp'able from ftp.wu-wien.ac.at as
677pub/src/X11/wafe/wafe-1.0.tar.gz-prerelease.
678
6794.12. Q. Are there any interfaces to commercial database in Python?
680
681A. There's an interface to SYBASE by John Redford
682<jredford@lehman.com>.
683
684There's also an interface to metalbase by Lance Ellinghouse
685<lance@markv.com>.
686
Guido van Rossumc24da7c1994-09-23 14:08:41 +00006874.13. Q. Is it possible to write obfuscated one-liners in Python?
688
689A. Yes. See the following three examples, due to Ulf Bartelt:
690
691# Primes < 1000
692print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,\
693map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000)))
694
695# First 10 Fibonacci numbers
696print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),\
697range(10))
698
699# Mandelbrot set
700print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,\
701Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,\
702Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,\
703i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y\
704>=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(\
70564+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy\
706))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)
707# \___ ___/ \___ ___/ | | |__ lines on screen
708# V V | |______ columns on screen
709# | | |__________ maximum of "iterations"
710# | |_________________ range on y axis
711# |____________________________ range on x axis
712
713Don't try this at home, kids!
714
715
Guido van Rossuma7925f11994-01-26 10:20:16 +0000716
7175. Extending Python
718===================
719
7205.1. Q. Can I create my own functions in C?
721
722A. Yes, you can create built-in modules containing functions,
Guido van Rossum24349991994-02-02 14:12:45 +0000723variables, exceptions and even new types in C. This is explained in
724the document "Extending and Embedding the Python Interpreter" (the
725LaTeX file Doc/ext.tex). Also read the chapter on dynamic loading.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000726
7275.2. Q. Can I create my own functions in C++?
728
729A. Yes, using the C-compatibility features found in C++. Basically
730you place extern "C" { ... } around the Python include files and put
731extern "C" before each function that is going to be called by the
732Python interpreter. Global or static C++ objects with constructors
733are probably not a good idea.
734
Guido van Rossum7ce61c11994-06-13 15:13:56 +00007355.3. Q. How can I execute arbitrary Python statements from C?
736
737A. The highest-level function to do this is run_command() which takes
738a single string argument which is executed in the context of module
739__main__ and returns 0 for success and -1 when an exception occurred
740(including SyntaxError). If you want more control, use run_string();
741see the source for run_command() in Python/pythonrun.c.
742
7435.4. Q. How can I evaluate an arbitrary Python expression from C?
744
745A. Call the function run_string() from the previous question with the
746start symbol eval_input; it then parses an expression, evaluates it
747and returns its value. See exec_eval() in Python/bltinmodule.c.
748
7495.5. Q. How do I extract C values from a Python object?
750
751A. That depends on the object's type. If it's a tuple,
752gettuplesize(o) returns its length and gettupleitem(o, i) returns its
753i'th item; similar for lists with getlistsize(o) and getlistitem(o,
754i). For strings, getstringsize(o) returns its length and
755getstringvalue(o) a pointer to its value (note that Python strings may
756contain null bytes so strlen() is not safe). To test which type an
757object is, first make sure it isn't NULL, and then use
758is_stringobject(o), is_tupleobject(o), is_listobject(o) etc.
759
7605.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
761
762A. You can't. Use t = newtupleobject(n) instead, and fill it with
763objects using settupleitem(t, i, o) -- note that this "eats" a
764reference count of o. Similar for lists with newlistobject(n) and
765setlistitem(l, i, o).
766
Guido van Rossuma7925f11994-01-26 10:20:16 +0000767
7686. Python's design
769==================
770
7716.1. Q. Why isn't there a generic copying operation for objects in
772Python?
773
774A. Hmm. Maybe there should be one, but it's difficult to assign a
775useful meaning to copying of open files, sockets and windows, or
776recursive data structures. As long as you design all your classes
777yourself you are of course free to define a standard base class that
778defines an overridable copying operation for all the objects you care
779about. (One practical point: it would have to be a built-in function,
780not a standard method name, since not all built-in object types have
781methods; e.g. strings, integers and tuples don't.)
782
7836.2. Q. Why isn't there a generic way to implement persistent objects
784in Python? (Persistent == automatically saved to and restored from
785disk.)
786
787A. Hmm, hmm. Basically for the same reasons as why there is no
788generic copying operation.
789
7906.3. Q. Why isn't there a switch or case statement in Python?
791
792A. You can do this easily enough with a sequence of
793if... elif... elif... else. There have been some proposals for switch
794statement syntax, but there is no concensus (yet) on whether and how
795to do range tests.
796
Guido van Rossumc50158e1994-05-31 09:18:50 +00007976.4. Q. Why does Python use indentation for grouping of statements?
798
799A. Basically I believe that using indentation for grouping is
800extremely elegant and contributes a lot to the clarity of the average
801Python program. Most people learn to love this feature after a while.
802Some arguments for it:
803
804- Since there are no begin/end brackets there cannot be a disagreement
805between grouping perceived by the parser and the human reader. I
806remember long ago seeing a C fragment like this:
807
808 if (x <= y)
809 x++;
810 y--;
811 z++;
812
813and staring a long time at it wondering why y was being decremented
814even for x > y... (And I wasn't a C newbie then either.)
815
816- Since there are no begin/end brackets there can be no conflicting
817coding styles. In C there are loads of different ways to place the
818braces (including the choice whether to place braces around single
819statements in certain cases, for consistency). If you're used to
820reading (and writing) code that uses one style, you will feel at least
821slightly uneasy when reading (or being required to write) another
822style.
823
824- Many coding styles place begin/end brackets on a line by themself.
825This makes programs considerably longer and wastes valuable screen
826space, making it harder to get a good overview over a program.
827Ideally, a function should fit on one basic tty screen (say, 20
828lines). 20 lines of Python are worth a LOT more than 20 lines of C.
829This is not solely due to the lack of begin/end brackets (the lack of
830declarations also helps, and the powerful operations of course), but
831it certainly helps!
832
Guido van Rossum3de27361994-07-25 14:19:33 +00008336.5. Q. Why are Python strings immutable?
834
835A. There are two advantages. One is performance: knowing that a
836string is immutable makes it easy to lay it out at construction time
837-- fixed and unchanging storage requirements. (This is also one of
838the reasons for the the distinction between tuples and lists.) The
839other is that strings in Python are considered as "elemental" as
840numbers. No amount of activity will change the value 8 to anything
841else, and in Python, no amount of activity will change the string
842"eight" to anything else. (Adapted from Jim Roskind)
843
8446.6. Q. Why don't strings have methods like index() or sort(), like
845lists?
846
847A. Good question. Strings currently don't have methods at all
848(likewise tuples and numbers). Long ago, it seemed unnecessary to
849implement any of these functions in C, so a standard library module
850"string" written in Python was created that performs string related
851operations. Since then, the cry for performance has moved most of
852them into the built-in module strop (this is imported by module
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000853string, which is still the preferred interface, without loss of
Guido van Rossum3de27361994-07-25 14:19:33 +0000854performance except during initialization). Some of these functions
855(e.g. index()) could easily be implemented as string methods instead,
856but others (e.g. sort()) can't, since their interface prescribes that
857they modify the object, while strings are immutable (see the previous
858question).
859
8606.7. Q. Why does Python use methods for some functionality
861(e.g. list.index()) but functions for other (e.g. len(list))?
862
863A. Functions are used for those operations that are generic for a
864group of types and which should work even for objects that don't have
865methods at all (e.g. numbers, strings, tuples). Also, implementing
866len(), max(), min() as a built-in function is actually less code than
867implementing them as methods for each type. One can quibble about
868individual cases but it's really too late to change such things
869fundamentally now.
870
8716.8. Q. Why can't I derive a class from built-in types (e.g. lists or
872files)?
873
874A. This is caused by the relatively late addition of (user-defined)
875classes to the language -- the implementation framework doesn't easily
876allow it. See the answer to question 4.2 for a work-around. This
877*may* be fixed in the (distant) future.
878
8796.9. Q. Why must 'self' be declared and used explicitly in method
880definitions and calls?
881
882A. By asking this question you reveal your C++ background. :-)
883When I added classes, this was (again) the simplest way of
884implementing methods without too many changes to the interpreter. I
885borrowed the idea from Modula-3. It turns out to be very useful, for
886a variety of reasons.
887
888First, it makes it more obvious that you are using a method or
889instance attribute instead of a local variable. Reading "self.x" or
890"self.meth()" makes it absolutely clear that an instance variable or
891method is used even if you don't know the class definition by heart.
892In C++, you can sort of tell by the lack of a local variable
893declaration (assuming globals are rare or reasily recognizable) -- but
894in Python, there are no local variable declarations, so you'd have to
895look up the class definition to be sure.
896
897Second, it means that no special syntax is necessary if you want to
898explicitly reference or call the method from a particular class. In
899C++, if you want to use a method from base class that is overridden in
900a derived class, you have to use the :: operator -- in Python you can
901write baseclass.methodname(self, <argument list>). This is
902particularly useful for __init__() methods, and in general in cases
903where a derived class method wants to extend the base class method of
904the same name and thus has to call the base class method somehow.
905
906Lastly, for instance variables, it solves a syntactic problem with
907assignment: since local variables in Python are (by definition!) those
908variables to which a value assigned in a function body (and that
909aren't explicitly declared global), there has to be some way to tell
910the interpreter that an assignment was meant to assign to an instance
911variable instead of to a local variable, and it should preferably be
912syntactic (for efficiency reasons). C++ does this through
913declarations, but Python doesn't have declarations and it would be a
914pity having to introduce them just for this purpose. Using the
915explicit "self.var" solves this nicely. Similarly, for using instance
916variables, having to write "self.var" means that references to
917unqualified names inside a method don't have to search the instance's
918directories.
919
Guido van Rossuma7925f11994-01-26 10:20:16 +0000920
9217. Using Python on non-UNIX platforms
922=====================================
923
Guido van Rossum91f60831994-02-15 15:52:27 +00009247.1. Q. Is there a Mac version of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000925
Guido van Rossum91f60831994-02-15 15:52:27 +0000926A. Yes. It is on most ftp sites carrying Python as python.sea.hqx --
927this is a self-extracting archive containing the application binary as
928well as the Lib modules.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000929
Guido van Rossum91f60831994-02-15 15:52:27 +00009307.2. Q. Is there a DOS version of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000931
Guido van Rossum91f60831994-02-15 15:52:27 +0000932A. Yes. More than one, actually: 16python.exe runs in standard DOS
933mode on 186 CPUs or higher; 32python.exe uses a DOS extender and only
934runs on a 386 or higher CPUs. Although 16python.exe does not pass the
935test set because test_grammar is too big for the parser, it actually
936has about 270 kbyte of allocatable heap space, which is sufficient for
937fairly large programs. 32python.exe is distributed as a tar file
938containing the required DOS extended and 387 emulator. Both are on
939most ftp sites carrying Python.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000940
Guido van Rossum91f60831994-02-15 15:52:27 +00009417.3. Q. Is there a Windows version of Python?
942
943A. Yes. Use qwpython.exe. The only problem with it: ^C
944unconditionally kills the entire program -- it does not raise
945KeyboardInterrupt. You can also run 16python.exe or 32python.exe in a
946"DOS box", but qwpython.exe appears to be slightly faster.
947
9487.4. Q. Is there a Windows NT version of Python?
949
950A. Yes. Use ntpython.exe. This is for Intel CPUs. If you want a
951Windows user interface, use qwpython.exe.
952
Guido van Rossum7ce61c11994-06-13 15:13:56 +00009537.5. Q. Is there an OS/2 version of Python?
954
955A. Yes. You can ftp it (from ftp.cwi.nl in pub/python, or from the
956mirror sites) as pyth_os2.zip. This contains both an executable and
957Makefiles for those fortunate enough to have a C compiler.
958
9597.6. Q. I have the PC version but it appears to be only a binary.
960Where's the library?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000961
962A. You still need to copy the files from the distribution directory
Guido van Rossum91f60831994-02-15 15:52:27 +0000963"python/Lib" to your system. If you don't have the full distribution,
Guido van Rossum3de27361994-07-25 14:19:33 +0000964you can get the file pythonlib<version>.tar.gz from most ftp sites
965carrying Python; this is a subset of the distribution containing just
966those file.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000967
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000968Once you have installed the library, you need to point sys.path to it.
969Assuming the library is in C:\misc\python\lib, the following commands
970will point your Python interpreter to it (note the doubled backslashes
971-- you can also use single forward slashes instead):
972
973 >>> import sys
974 >>> sys.path.insert(0, 'C:\\misc\\python\\lib')
975 >>>
976
977For a more permanent effect, set the environment variable PYTHONPATH,
978as follows (talking to a DOS prompt):
979
980 C> SET PYTHONPATH=C:\misc\python\lib
981
Guido van Rossum7ce61c11994-06-13 15:13:56 +00009827.7. Q. Where's the documentation for the Mac or PC version?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000983
984A. There isn't any. The documentation for the Unix version also
Guido van Rossum91f60831994-02-15 15:52:27 +0000985applies to the Mac and PC versions. Where applicable, differences
Guido van Rossuma7925f11994-01-26 10:20:16 +0000986are indicated in the text.
987
Guido van Rossum7ce61c11994-06-13 15:13:56 +00009887.8. Q. The Mac (PC) version doesn't seem to have any facilities for
Guido van Rossum91f60831994-02-15 15:52:27 +0000989creating or editing programs apart from entering it interactively, and
990there seems to be no way to save code that was entered interactively.
991How do I create a Python program on the Mac (PC)?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000992
Guido van Rossum91f60831994-02-15 15:52:27 +0000993A. Use an external editor. On the Mac, I am quite happy with the Desk
994Accessory called Sigma Edit; this doesn't require Multifinder or
995System 7. I work like this: start the interpreter; edit a module file
996using Sigma Edit; import and test it in the interpreter; edit again in
997Sigma Edit; then use the built-in function reload() to re-read the
998imported module; etc.
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000999
1000Regarding the same question for the PC, Kurt Wm. Hemr writes: "While
1001anyone with a pulse could certainly figure out how to do the same on
1002MS-Windows, I would recommend the NotGNU Emacs clone for MS-Windows.
1003Not only can you easily resave and "reload()" from Python after making
1004changes, but since WinNot auto-copies to the clipboard any text you
1005select, you can simply select the entire procedure (function) which
1006you changed in WinNot, switch to QWPython, and shift-ins to reenter
1007the changed program unit."