blob: e884fa96ec85fed64c3a7fd069b6e0db63c617f5 [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 Rossuma7925f11994-01-26 10:20:16 +0000119
120 5. Extending Python
121 5.1. Q. Can I create my own functions in C?
122 5.2. Q. Can I create my own functions in C++?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000123 5.3. Q. How can I execute arbitrary Python statements from C?
124 5.4. Q. How can I evaluate an arbitrary Python expression from C?
125 5.5. Q. How do I extract C values from a Python object?
126 5.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000127
128 6. Python's design
129 6.1. Q. Why isn't there a generic copying operation for objects in
130 Python?
131 6.2. Q. Why isn't there a generic way to implement persistent objects
132 in Python? (Persistent == automatically saved to and restored from
133 disk.)
134 6.3. Q. Why isn't there a switch or case statement in Python?
Guido van Rossumc50158e1994-05-31 09:18:50 +0000135 6.4. Q. Why does Python use indentation for grouping of statements?
Guido van Rossum3de27361994-07-25 14:19:33 +0000136 6.5. Q. Why are Python strings immutable?
137 6.6. Q. Why don't strings have methods like index() or sort(), like
138 lists?
139 6.7. Q. Why does Python use methods for some functionality
140 (e.g. list.index()) but functions for other (e.g. len(list))?
141 6.8. Q. Why can't I derive a class from built-in types (e.g. lists or
142 files)?
143 6.9. Q. Why must 'self' be declared and used explicitly in method
144 definitions and calls?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000145
146 7. Using Python on non-UNIX platforms
Guido van Rossum91f60831994-02-15 15:52:27 +0000147 7.1. Q. Is there a Mac version of Python?
148 7.2. Q. Is there a DOS version of Python?
149 7.3. Q. Is there a Windows version of Python?
150 7.4. Q. Is there a Windows NT version of Python?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000151 7.5. Q. Is there an OS/2 version of Python?
152 7.6. Q. I have the PC version but it appears to be only a binary.
153 Where's the library?
154 7.7. Q. Where's the documentation for the Mac or PC version?
155 7.8. Q. The Mac (PC) version doesn't seem to have any facilities for
Guido van Rossum91f60831994-02-15 15:52:27 +0000156 creating or editing programs apart from entering it interactively, and
157 there seems to be no way to save code that was entered interactively.
158 How do I create a Python program on the Mac (PC)?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000159
160To find a particular question, search for the question number followed
161by a dot, a space, and a Q at the beginning of a line (e.g. to find
162question 4.2 in vi, type /^4\.2\. Q/).
163
164
1651. General information and availability
166=======================================
167
1681.1. Q. What is Python?
169
170A. Python is an interpreted, interactive, object-oriented programming
171language. It incorporates modules, exceptions, dynamic typing, very
172high level dynamic data types, and classes. Python combines
173remarkable power with very clear syntax. It has interfaces to many
174system calls and libraries, as well as to various window systems, and
175is extensible in C or C++. It is also usable as an extension language
176for applications that need a programmable interface. Finally, Python
177is portable: it runs on many brands of UNIX, on the Mac, and on
178MS-DOS.
179
180To find out more, the best thing to do is to start reading the
181tutorial from the documentation set (see a few questions further
182down).
183
1841.2. Q. Why is it called Python?
185
186A. Apart from being a computer wizard, I'm also a fan of "Monty
187Python's Flying Circus" (a BBC comedy series from the seventies, in
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000188the -- unlikely -- case you didn't know). It occurred to me one day
189that I needed a name that was short, unique, and slightly mysterious.
190And I happened to be reading some scripts from the series at the
191time... So then I decided to call my language Python. But Python is
192not a joke. And don't you associate it with dangerous reptiles
193either!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000194
1951.3. Q. How do I obtain a copy of the Python source?
196
197A. The latest Python source distribution is always available by
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000198anonymous ftp from ftp.cwi.nl [192.16.191.128] in the directory
Guido van Rossum44b4cb11994-05-04 13:28:51 +0000199/pub/python, with filename python<version>.tar.gz. (Old versions may
200have an extension of .Z, indicating use of "compress" compression.)
201It is a gzip'ed tar file containing the complete C source, LaTeX
202documentation, Python library modules, example programs, and several
203useful pieces of freely distributable software. This will compile and
Guido van Rossum3de27361994-07-25 14:19:33 +0000204run out of the box on most UNIX platforms. (See section 7 for
205non-UNIX information.)
Guido van Rossuma7925f11994-01-26 10:20:16 +0000206
2071.4. Q. How do I get documentation on Python?
208
209A. The latest Python documentation set is always available by
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000210anonymous ftp from ftp.cwi.nl [192.16.191.128] in the directory
Guido van Rossum44b4cb11994-05-04 13:28:51 +0000211/pub/python, with filename pythondoc-ps<version>.tar.gz. It is a
212gzip'ed tar file containing PostScript files of the reference manual,
Guido van Rossum3de27361994-07-25 14:19:33 +0000213the library manual, and the tutorial. Note that the library manual is
214the most important one of the set, as much of Python's power stems
215from the standard or built-in types, functions and modules, all of
216which are described here. PostScript for a high-level description of
217Python is in the file nluug-paper.ps.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000218
Guido van Rossumc50158e1994-05-31 09:18:50 +00002191.5. Q. Are there other ftp sites that mirror the Python distribution?
220
221A. The following sites keep mirrors of the Python distribution:
Guido van Rossuma7925f11994-01-26 10:20:16 +0000222
223Site IP address Directory
224
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000225gatekeeper.dec.com 16.1.0.2 /pub/plan/python
Guido van Rossuma7925f11994-01-26 10:20:16 +0000226ftp.uu.net 192.48.96.9 /languages/python
227ftp.wustl.edu 128.252.135.4 /graphics/graphics/sgi-stuff/python
Guido van Rossumc50158e1994-05-31 09:18:50 +0000228ftp.funet.fi 128.214.6.100 /pub/languages/python
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000229ftp.fu-berlin.de 130.133.1.18 /unix/languages/python (*python* only)
Guido van Rossumc50158e1994-05-31 09:18:50 +0000230ftp.sunet.se 130.238.127.3 /pub/lang/python
Guido van Rossumea2c6f71994-07-14 12:35:14 +0000231unix.hensa.ac.uk 129.12.43.16 /uunet/languages/python
Guido van Rossuma7925f11994-01-26 10:20:16 +0000232
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000233Or try archie on e.g. python1.0 to locate the nearest copy of that
234version...
Guido van Rossuma7925f11994-01-26 10:20:16 +0000235
Guido van Rossumc50158e1994-05-31 09:18:50 +00002361.6. Q. Is there a newsgroup or mailing list devoted to Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000237
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000238A. There is a newsgroup, comp.lang.python, and a mailing list. The
239newsgroup and mailing list are gatewayed into each other -- if you can
240read news it is not necessary to subscribe to the mailing list. Send
241e-mail to python-list-request@cwi.nl to (un)subscribe to the mailing
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000242list. Once you're on, send e-mail tp python-list@cwi.nl to send mail
243to the entire mailing list and newsgroup.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000244
Guido van Rossumc50158e1994-05-31 09:18:50 +00002451.7. Q. Is there a book on Python, or will there be one out soon?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000246
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000247A. Unfortunately, not yet. Mark Lutz and I are planning to write one,
248but we are still a in very preliminary stage. If you would like to
249beat us at it and get rich from book royalties, go ahead!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000250
Guido van Rossumc50158e1994-05-31 09:18:50 +00002511.8. Q. Are there any published articles about Python that I can quote?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000252
253A. So far the only refereed and published article that describes
254Python in some detail is:
255
256 Guido van Rossum and Jelke de Boer, "Interactively Testing Remote
257 Servers Using the Python Programming Language", CWI Quarterly, Volume
258 4, Issue 4 (December 1991), Amsterdam, pp 283-303.
259
260LaTeX source for this paper is available as part of the Python source
261distribution.
262
263A more recent high-level description of Python is:
264
265 Guido van Rossum, "An Introduction to Python for UNIX/C
266 Programmers", in the proceedings of the NLUUG najaarsconferentie
267 1993 (dutch UNIX users group meeting november 1993).
268
269PostScript for this paper and for the slides used for the accompanying
270presentation can be found in the ftp directory mentioned a few
271questions earlier, with filenames nluug-paper.ps and nluug-slides.ps,
272respectively.
273
Guido van Rossumc50158e1994-05-31 09:18:50 +00002741.9. Q. How does the Python version numbering scheme work?
Guido van Rossum95f61a71994-01-26 17:23:37 +0000275
276A. Python versions are numbered A.B.C. A is the major version number
277-- it is only incremented for major changes in functionality or source
278structure. B is the minor version number, incremented for less
279earth-shattering changes to a release. C is the patchlevel -- it is
280incremented for each new release. Note that in the past, patches have
281added significant changes; in fact the changeover from 0.9.9 to 1.0.0
282was the first time that either A or B changed!
283
Guido van Rossumc50158e1994-05-31 09:18:50 +00002841.10. Q. Are there other ftp sites that carry Python related material?
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000285
286A. An interesting ftp site for Python users is ftp.markv.com
287(192.122.251.1); the directory pub/python contains a growing
288collection of interesting Python scripts. To submit a script for
289inclusion, place it together with a readme file (with extension
290.readme) in the publicly writable directory /incoming/python. This
291service is maintained by Lance Ellinghouse <lance@markv.com>.
292
Guido van Rossum7ce61c11994-06-13 15:13:56 +00002931.11. Q. Are there copyright restrictions on the use of Python?
294
295A. Hardly. You can do anything you want with the source, as long as
296you leave the copyrights in, display those copyrights in any
297documentation about Python that you produce, don't use the author's
298institute's name in publicity without prior written permission, and
299don't hold them responsible for anything (read the actual copyright
300for a precise legal wording).
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000301
Guido van Rossuma7925f11994-01-26 10:20:16 +0000302
3032. Python in the real world
304===========================
305
3062.1. Q. How many people are using Python?
307
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000308A. I don't know, but the maximum number of simultaneous subscriptions
309to the Python mailing list before it was gatewayed into the newsgroup
310was about 180 (several of which were local redistribution lists). I
311believe that many active Python users don't bother to subscribe to the
312list, and now that there's a newsgroup the mailing list subscription
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000313is even less meaningful. I see new names on the newsgroup all the
314time and my best guess is that there are currently at least several
315thousands of users.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000316
3172.2. Q. Have any significant projects been done in Python?
318
319A. Here at CWI (the home of Python), we have written a 20,000 line
320authoring environment for transportable hypermedia presentations, a
Guido van Rossum5333c5d1994-04-11 11:06:22 +00003215,000 line multimedia teleconferencing tool, as well as many many
322smaller programs.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000323
324The University of Virginia uses Python to control a virtual reality
325engine. Contact: Matt Conway <conway@virginia.edu>.
326
327See also the next question.
328
3292.3. Q. Are there any commercial projects going on using Python?
330
331A. Several companies have revealed to me that they are planning or
332considering to use Python in a future product. The furthest is
333Sunrise Software, who already have a product out using Python -- they
334use Python for a GUI management application and an SNMP network
335manangement application. Contact: <info@sunrise.com>.
336
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000337Infoseek is using python to implement their commercial WWW information
338retrieval service. Contact: <info@infoseek.com>.
339
Guido van Rossuma7925f11994-01-26 10:20:16 +0000340Individuals at many other companies are using Python for
341internal development (witness their contributions to the Python
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000342mailing list or newsgroup).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000343
344Python has also been elected as an extension language by MADE, a
345consortium supported by the European Committee's ESPRIT program and
346consisting of Bull, CWI and some other European companies. Contact:
347Ivan Herman <ivan@cwi.nl>.
348
Guido van Rossum95f61a71994-01-26 17:23:37 +00003492.4. Q. How stable is Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000350
Guido van Rossum3de27361994-07-25 14:19:33 +0000351A. Very stable. While the current version number would suggest it is
352in the early stages of development, in fact new, stable releases
353(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 +0000354months for the past four years.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000355
Guido van Rossum95f61a71994-01-26 17:23:37 +00003562.5. Q. What new developments are expected for Python in the future?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000357
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000358A. A proposal is being worked out to change the semantics of operator
359overloading (__add__, __mul__ etc.) to make them more useful for
360implementing types that don't resemble numbers. Additions will be
361__call__ (to call an instance as if it were a function) and __eq__,
362_lt__ etc. (to override individual comparisons). A (new) pthreads
363interface has been submitted which will be integrated in the next
364release. The X11/Motif interface will be improved. There are ideas
365about built-in help using strings placed into function objects, and
366possibly a switch statement.
367
368There will be better ports to the Mac, DOS, Windows, Windows NT, and
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000369OS/2. The Windows ports will support dynamically loaded modules using
370DLLs. There may be a Windows version of STDWIN (someone has actually
371written one and contributed it but it's not robust enough at the
372moment).
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000373
374Also planned is improved support for embedding Python in other
375applications, e.g. by renaming most global symbols to have a "Py"
376prefix and providing more documentation and threading support.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000377
Guido van Rossum3de27361994-07-25 14:19:33 +00003782.6. Q. Is it reasonable to propose incompatible changes to Python?
379
380A. In general, no. There are already millions of lines of Python code
381around the world, so any changes in the language that invalidates more
382than a very small fraction of existing programs has to be frowned
383upon. Even if you can provide a conversion program, there still is
384the problem of updating all documentation. Providing a gradual
385upgrade path is the only way if a feature has to be changed.
386
Guido van Rossuma7925f11994-01-26 10:20:16 +0000387
3883. Building Python
389==================
390
Guido van Rossum91f60831994-02-15 15:52:27 +00003913.1. Q. Is there a test set?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000392
393A. Yes, simply do "import testall" (or "import autotest" if you aren't
394interested in the output). The standard modules whose name begins
395with "test" together comprise the test. The test set doesn't test
396*all* features of Python but it goes a long way to confirm that a new
397port is actually working. The Makefile contains an entry "make test"
398which runs the autotest module.
399
Guido van Rossum91f60831994-02-15 15:52:27 +00004003.2. Q. When running the test set, I get complaints about floating point
Guido van Rossuma7925f11994-01-26 10:20:16 +0000401operations, but when playing with floating point operations I cannot
402find anything wrong with them.
403
404A. The test set makes occasional unwarranted assumptions about the
405semantics of C floating point operations. Until someone donates a
406better floating point test set, you will have to comment out the
407offending floating point tests and execute similar tests manually.
408
Guido van Rossum91f60831994-02-15 15:52:27 +00004093.3. Q. Link errors building Python with STDWIN on SGI IRIX.
Guido van Rossum24349991994-02-02 14:12:45 +0000410
411A. Rebuild STDWIN, specifying "CC=cc -cckr" in the Makefile.
412
Guido van Rossum91f60831994-02-15 15:52:27 +00004133.4. Q. Link errors after rerunning the configure script.
Guido van Rossum24349991994-02-02 14:12:45 +0000414
415A. It is generally necessary to run "make clean" after a configuration
416change.
417
Guido van Rossum91f60831994-02-15 15:52:27 +00004183.5. Q. The python interpreter complains about options passed to a
Guido van Rossum24349991994-02-02 14:12:45 +0000419script (after the script name).
420
421A. You are probably linking with GNU getopt, e.g. through -liberty.
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000422Don't. The reason for the complaint is that GNU getopt, unlike System
423V getopt and other getopt implementations, doesn't consider a
424non-option to be the end of the option list. A quick (and compatible)
425fix for scripts is to add "--" to the interpreter, like this:
426
427 #! /usr/local/bin/python --
428
429You can also use this interactively:
430
431 python -- script.py [options]
Guido van Rossum24349991994-02-02 14:12:45 +0000432
Guido van Rossum91f60831994-02-15 15:52:27 +00004333.6. Q. When building on the SGI, make tries to run python to create
Guido van Rossum24349991994-02-02 14:12:45 +0000434glmodule.c, but python hasn't been built or installed yet.
435
436A. Comment out the line mentioning glmodule.c in Setup and build a
437python without gl first; install it or make sure it is in your $PATH,
438then edit the Setup file again to turn on the gl module, and make
439again. You don't need to do "make clean"; you do need to run "make
440Makefile" in the Modules subdirectory (or just run "make" at the
441toplevel).
442
Guido van Rossum3de27361994-07-25 14:19:33 +00004433.7. Q. Python built with gcc for the DEC Alpha doesn't work.
444
445People have reported problems with both gcc 2.5.8 and 2.6.0. The DEC
446OSF/1 cc compiler does not have these problems so it's probably gcc's
447fault. One person reported that the problem went away when using -g
448instead of -O so this may be an option if you insist on using gcc. If
449someone tracks it down more completely I'd like to hear about it!
450
4513.8. Q. Other trouble building Python on platform X.
Guido van Rossum95f61a71994-01-26 17:23:37 +0000452
453A. Please email the details to <guido@cwi.nl> and I'll look into it.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000454
455
4564. Programming in Python
457========================
458
Guido van Rossum24349991994-02-02 14:12:45 +00004594.1. Q. Is there a source code level debugger with breakpoints, step,
460etc.?
461
462A. Yes. Check out module pdb; pdb.help() prints the documentation (or
463you can read it as Lib/pdb.doc). If you use the STDWIN option,
464there's also a windowing interface, wdb. You can write your own
465debugger by using the code for pdb or wdb as an example.
466
4674.2. Q. Can I create an object class with some methods implemented in
Guido van Rossuma7925f11994-01-26 10:20:16 +0000468C and others in Python (e.g. through inheritance)? (Also phrased as:
469Can I use a built-in type as base class?)
470
471A. No, but you can easily create a Python class which serves as a
472wrapper around a built-in object, e.g. (for dictionaries):
473
474 # A user-defined class behaving almost identical
475 # to a built-in dictionary.
476 class UserDict:
477 def __init__(self): self.data = {}
478 def __repr__(self): return repr(self.data)
479 def __cmp__(self, dict):
480 if type(dict) == type(self.data):
481 return cmp(self.data, dict)
482 else:
483 return cmp(self.data, dict.data)
484 def __len__(self): return len(self.data)
485 def __getitem__(self, key): return self.data[key]
486 def __setitem__(self, key, item): self.data[key] = item
487 def __delitem__(self, key): del self.data[key]
488 def keys(self): return self.data.keys()
489 def items(self): return self.data.items()
490 def values(self): return self.data.values()
491 def has_key(self, key): return self.data.has_key(key)
492
Guido van Rossum24349991994-02-02 14:12:45 +00004934.3. Q. Is there a curses/termcap package for Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000494
495A. No, but you can use the "alfa" (== character cell) version of
496STDWIN. (STDWIN == Standard Windows, a portable windowing system
Guido van Rossum91f60831994-02-15 15:52:27 +0000497interface by the same author, URL: ftp://ftp.cwi.nl/pub/stdwin.)
Guido van Rossuma7925f11994-01-26 10:20:16 +0000498This will also prepare your program for porting to windowing
499environments such as X11 or the Macintosh.
500
Guido van Rossum24349991994-02-02 14:12:45 +00005014.4. Q. Is there an equivalent to C's onexit() in Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000502
503A. Yes, if you import sys and assign a function to sys.exitfunc, it
504will be called when your program exits, is killed by an unhandled
505exception, or (on UNIX) receives a SIGHUP or SIGTERM signal.
506
Guido van Rossum24349991994-02-02 14:12:45 +00005074.5. Q. When I define a function nested inside another function, the
Guido van Rossuma7925f11994-01-26 10:20:16 +0000508nested function seemingly can't access the local variables of the
509outer function. What is going on? How do I pass local data to a
510nested function?
511
512A. Python does not have arbitrarily nested scopes. When you need to
513create a function that needs to access some data which you have
514available locally, create a new class to hold the data and return a
515method of an instance of that class, e.g.:
516
517 class MultiplierClass:
518 def __init__(self, factor):
519 self.factor = factor
520 def multiplier(self, argument):
521 return argument * self.factor
522
523 def generate_multiplier(factor):
524 return MultiplierClass(factor).multiplier
525
526 twice = generate_multiplier(2)
527 print twice(10)
528 # Output: 20
529
Guido van Rossum24349991994-02-02 14:12:45 +00005304.6. Q. How do I iterate over a sequence in reverse order?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000531
532A. If it is a list, the fastest solution is
533
534 list.reverse()
535 try:
536 for x in list:
537 "do something with x"
538 finally:
539 list.reverse()
540
541This has the disadvantage that while you are in the loop, the list
542is temporarily reversed. If you don't like this, you can make a copy.
543This appears expensive but is actually faster than other solutions:
544
545 rev = list[:]
546 rev.reverse()
547 for x in rev:
548 <do something with x>
549
550If it isn't a list, a more general but slower solution is:
551
552 i = len(list)
553 while i > 0:
554 i = i-1
555 x = list[i]
556 <do something with x>
557
558A more elegant solution, is to define a class which acts as a sequence
559and yields the elements in reverse order (solution due to Steve
560Majewski):
561
562 class Rev:
563 def __init__(self, seq):
564 self.forw = seq
565 def __len__(self):
566 return len(self.forw)
567 def __getitem__(self, i):
568 return self.forw[-(i + 1)]
569
570You can now simply write:
571
572 for x in Rev(list):
573 <do something with x>
574
575Unfortunately, this solution is slowest of all, due the the method
576call overhead...
577
Guido van Rossum24349991994-02-02 14:12:45 +00005784.7. Q. My program is too slow. How do I speed it up?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000579
580A. That's a tough one, in general. There are many tricks to speed up
581Python code; I would consider rewriting parts in C only as a last
582resort. One thing to notice is that function and (especially) method
583calls are rather expensive; if you have designed a purely OO interface
584with lots of tiny functions that don't do much more than get or set an
585instance variable or call another method, you may consider using a
586more direct way, e.g. directly accessing instance variables. Also see
587the standard module "profile" (described in the file
588"python/lib/profile.doc") which makes it possible to find out where
589your program is spending most of its time (if you have some patience
590-- the profiling itself can slow your program down by an order of
591magnitude).
592
Guido van Rossum24349991994-02-02 14:12:45 +00005934.8. Q. When I have imported a module, then edit it, and import it
Guido van Rossuma7925f11994-01-26 10:20:16 +0000594again (into the same Python process), the changes don't seem to take
595place. What is going on?
596
597A. For efficiency reasons, Python only reads the module file on the
598first time a module is imported (otherwise a program consisting of
599many modules, each of which imports the same basic module, would read
600the basic module over and over again). To force a changed module
601being read again, do this:
602
603 import modname
604 reload(modname)
605
606Warning: this technique is not 100% fool-proof. In particular,
607modules containing statements like
608
609 from modname import some_objects
610
611will continue to work with the old version of the objects imported
612thus.
613
Guido van Rossum24349991994-02-02 14:12:45 +00006144.9. Q. I have a module in which I want to execute some extra code when it
615is run as a script. How do I find out whether I am running as a
616script?
617
618A. A module can find out its own module name by alooking at the
619(predefined) global variable __name__. If this has the value
620'__main__' you are running as a script. E.g. if you put the following
621on the last line of your module, main() is called only when your
622module is running as a script:
623
624 if __name__ == '__main__': main()
625
Guido van Rossum7ce61c11994-06-13 15:13:56 +00006264.10. Q. I try to run a program from the Demo directory but it fails with
627ImportError: No module named ...; what gives?
628
629A. This is probably an optional module which hasn't been configured on
630your system. This especially happens with modules like "stdwin",
631"gl", "Xt" or "Xm". For stdwin and many other modules, see
632Modules/Setup.in for info on how to add these modules to your Python,
633if it is possible at all. Sometimes you will have to ftp and build
634another package first (e.g. stdwin). Sometimes the module only works
635on specific platforms (e.g. gl only works on SGI machines). For
636X-related modules (Xt and Xm) you will have to do more work: they are
637currently not part of the standard Python distribution. You will have
638to ftp the file "extensions.tar.gz" file from a Python ftp repository
639(e.g. ftp.cwi.nl) and follow the instructions there. Note: the X
640related modules are still somewhat flakey, so don't try this unless
641you know a bit or two about building X applications on your platform.
642
6434.11. Q. What GUI toolkits exist for Python?
644
645A. Depending on what platform(s) you are aiming at, there are several.
646
647- The standard Python distribution comes with an interface to STDWIN,
648a platform-independent low-level windowing interface (you have to ftp
649the source for stdwin separately, e.g. from ftp.cwi.nl in pub/stdwin
650or gatekeeper.dec.com in pub/misc/stdwin). STDWIN runs under X11 or
651the Mac; a Windows port is about to be released.
652
653- For SGI only, there's an interface to the complete GL (Graphics
654Library -- low level but very good 3D capabilities) as well as to
655FORMS (a buttons-and-sliders-etc package built on top of GL by Mark
656Overmars -- ftp'able from ftp.cs.ruu.nl in pub/SGI/FORMS).
657
658- There's an interface to X11, including the Athena and Motif widget
659sets (and a few individual widgets, like Mosaic's HTML widget and
660SGI's GL widget) in the Extensions set, which is separately ftp'able
661from ftp.cwi.nl as pub/python/extensions.tar.gz.
662
663- There's an interface to SUIT, the U of Virginia's Simple User
664Interface Toolkit; it can be ftp'ed from uvacs.cs.virginia.edu as
665pub/suit/python/SUIT_python.tar.Z. A PC binary of Python 1.0.2
666compiled with DJGPP and with SUIT support built-in has been made
667available by Antonio Costa on ftp site asterix.inescn.pt, directory
668pub/PC/python, file pyt102su.exe (a self-extracting archive).
669
670- There's a neat interface to the Tcl/Tk widget set; ftp it from
671ftp.cwi.nl as pub/python/tkinter.tar.gz.
672
673- There's an interface to WAFE, a Tcl interface to the X11 Motif and
674Athena widget sets. Last I heard about it it was included in the
675WAFE 1.0 prerelease, ftp'able from ftp.wu-wien.ac.at as
676pub/src/X11/wafe/wafe-1.0.tar.gz-prerelease.
677
6784.12. Q. Are there any interfaces to commercial database in Python?
679
680A. There's an interface to SYBASE by John Redford
681<jredford@lehman.com>.
682
683There's also an interface to metalbase by Lance Ellinghouse
684<lance@markv.com>.
685
Guido van Rossuma7925f11994-01-26 10:20:16 +0000686
6875. Extending Python
688===================
689
6905.1. Q. Can I create my own functions in C?
691
692A. Yes, you can create built-in modules containing functions,
Guido van Rossum24349991994-02-02 14:12:45 +0000693variables, exceptions and even new types in C. This is explained in
694the document "Extending and Embedding the Python Interpreter" (the
695LaTeX file Doc/ext.tex). Also read the chapter on dynamic loading.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000696
6975.2. Q. Can I create my own functions in C++?
698
699A. Yes, using the C-compatibility features found in C++. Basically
700you place extern "C" { ... } around the Python include files and put
701extern "C" before each function that is going to be called by the
702Python interpreter. Global or static C++ objects with constructors
703are probably not a good idea.
704
Guido van Rossum7ce61c11994-06-13 15:13:56 +00007055.3. Q. How can I execute arbitrary Python statements from C?
706
707A. The highest-level function to do this is run_command() which takes
708a single string argument which is executed in the context of module
709__main__ and returns 0 for success and -1 when an exception occurred
710(including SyntaxError). If you want more control, use run_string();
711see the source for run_command() in Python/pythonrun.c.
712
7135.4. Q. How can I evaluate an arbitrary Python expression from C?
714
715A. Call the function run_string() from the previous question with the
716start symbol eval_input; it then parses an expression, evaluates it
717and returns its value. See exec_eval() in Python/bltinmodule.c.
718
7195.5. Q. How do I extract C values from a Python object?
720
721A. That depends on the object's type. If it's a tuple,
722gettuplesize(o) returns its length and gettupleitem(o, i) returns its
723i'th item; similar for lists with getlistsize(o) and getlistitem(o,
724i). For strings, getstringsize(o) returns its length and
725getstringvalue(o) a pointer to its value (note that Python strings may
726contain null bytes so strlen() is not safe). To test which type an
727object is, first make sure it isn't NULL, and then use
728is_stringobject(o), is_tupleobject(o), is_listobject(o) etc.
729
7305.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
731
732A. You can't. Use t = newtupleobject(n) instead, and fill it with
733objects using settupleitem(t, i, o) -- note that this "eats" a
734reference count of o. Similar for lists with newlistobject(n) and
735setlistitem(l, i, o).
736
Guido van Rossuma7925f11994-01-26 10:20:16 +0000737
7386. Python's design
739==================
740
7416.1. Q. Why isn't there a generic copying operation for objects in
742Python?
743
744A. Hmm. Maybe there should be one, but it's difficult to assign a
745useful meaning to copying of open files, sockets and windows, or
746recursive data structures. As long as you design all your classes
747yourself you are of course free to define a standard base class that
748defines an overridable copying operation for all the objects you care
749about. (One practical point: it would have to be a built-in function,
750not a standard method name, since not all built-in object types have
751methods; e.g. strings, integers and tuples don't.)
752
7536.2. Q. Why isn't there a generic way to implement persistent objects
754in Python? (Persistent == automatically saved to and restored from
755disk.)
756
757A. Hmm, hmm. Basically for the same reasons as why there is no
758generic copying operation.
759
7606.3. Q. Why isn't there a switch or case statement in Python?
761
762A. You can do this easily enough with a sequence of
763if... elif... elif... else. There have been some proposals for switch
764statement syntax, but there is no concensus (yet) on whether and how
765to do range tests.
766
Guido van Rossumc50158e1994-05-31 09:18:50 +00007676.4. Q. Why does Python use indentation for grouping of statements?
768
769A. Basically I believe that using indentation for grouping is
770extremely elegant and contributes a lot to the clarity of the average
771Python program. Most people learn to love this feature after a while.
772Some arguments for it:
773
774- Since there are no begin/end brackets there cannot be a disagreement
775between grouping perceived by the parser and the human reader. I
776remember long ago seeing a C fragment like this:
777
778 if (x <= y)
779 x++;
780 y--;
781 z++;
782
783and staring a long time at it wondering why y was being decremented
784even for x > y... (And I wasn't a C newbie then either.)
785
786- Since there are no begin/end brackets there can be no conflicting
787coding styles. In C there are loads of different ways to place the
788braces (including the choice whether to place braces around single
789statements in certain cases, for consistency). If you're used to
790reading (and writing) code that uses one style, you will feel at least
791slightly uneasy when reading (or being required to write) another
792style.
793
794- Many coding styles place begin/end brackets on a line by themself.
795This makes programs considerably longer and wastes valuable screen
796space, making it harder to get a good overview over a program.
797Ideally, a function should fit on one basic tty screen (say, 20
798lines). 20 lines of Python are worth a LOT more than 20 lines of C.
799This is not solely due to the lack of begin/end brackets (the lack of
800declarations also helps, and the powerful operations of course), but
801it certainly helps!
802
Guido van Rossum3de27361994-07-25 14:19:33 +00008036.5. Q. Why are Python strings immutable?
804
805A. There are two advantages. One is performance: knowing that a
806string is immutable makes it easy to lay it out at construction time
807-- fixed and unchanging storage requirements. (This is also one of
808the reasons for the the distinction between tuples and lists.) The
809other is that strings in Python are considered as "elemental" as
810numbers. No amount of activity will change the value 8 to anything
811else, and in Python, no amount of activity will change the string
812"eight" to anything else. (Adapted from Jim Roskind)
813
8146.6. Q. Why don't strings have methods like index() or sort(), like
815lists?
816
817A. Good question. Strings currently don't have methods at all
818(likewise tuples and numbers). Long ago, it seemed unnecessary to
819implement any of these functions in C, so a standard library module
820"string" written in Python was created that performs string related
821operations. Since then, the cry for performance has moved most of
822them into the built-in module strop (this is imported by module
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000823string, which is still the preferred interface, without loss of
Guido van Rossum3de27361994-07-25 14:19:33 +0000824performance except during initialization). Some of these functions
825(e.g. index()) could easily be implemented as string methods instead,
826but others (e.g. sort()) can't, since their interface prescribes that
827they modify the object, while strings are immutable (see the previous
828question).
829
8306.7. Q. Why does Python use methods for some functionality
831(e.g. list.index()) but functions for other (e.g. len(list))?
832
833A. Functions are used for those operations that are generic for a
834group of types and which should work even for objects that don't have
835methods at all (e.g. numbers, strings, tuples). Also, implementing
836len(), max(), min() as a built-in function is actually less code than
837implementing them as methods for each type. One can quibble about
838individual cases but it's really too late to change such things
839fundamentally now.
840
8416.8. Q. Why can't I derive a class from built-in types (e.g. lists or
842files)?
843
844A. This is caused by the relatively late addition of (user-defined)
845classes to the language -- the implementation framework doesn't easily
846allow it. See the answer to question 4.2 for a work-around. This
847*may* be fixed in the (distant) future.
848
8496.9. Q. Why must 'self' be declared and used explicitly in method
850definitions and calls?
851
852A. By asking this question you reveal your C++ background. :-)
853When I added classes, this was (again) the simplest way of
854implementing methods without too many changes to the interpreter. I
855borrowed the idea from Modula-3. It turns out to be very useful, for
856a variety of reasons.
857
858First, it makes it more obvious that you are using a method or
859instance attribute instead of a local variable. Reading "self.x" or
860"self.meth()" makes it absolutely clear that an instance variable or
861method is used even if you don't know the class definition by heart.
862In C++, you can sort of tell by the lack of a local variable
863declaration (assuming globals are rare or reasily recognizable) -- but
864in Python, there are no local variable declarations, so you'd have to
865look up the class definition to be sure.
866
867Second, it means that no special syntax is necessary if you want to
868explicitly reference or call the method from a particular class. In
869C++, if you want to use a method from base class that is overridden in
870a derived class, you have to use the :: operator -- in Python you can
871write baseclass.methodname(self, <argument list>). This is
872particularly useful for __init__() methods, and in general in cases
873where a derived class method wants to extend the base class method of
874the same name and thus has to call the base class method somehow.
875
876Lastly, for instance variables, it solves a syntactic problem with
877assignment: since local variables in Python are (by definition!) those
878variables to which a value assigned in a function body (and that
879aren't explicitly declared global), there has to be some way to tell
880the interpreter that an assignment was meant to assign to an instance
881variable instead of to a local variable, and it should preferably be
882syntactic (for efficiency reasons). C++ does this through
883declarations, but Python doesn't have declarations and it would be a
884pity having to introduce them just for this purpose. Using the
885explicit "self.var" solves this nicely. Similarly, for using instance
886variables, having to write "self.var" means that references to
887unqualified names inside a method don't have to search the instance's
888directories.
889
Guido van Rossuma7925f11994-01-26 10:20:16 +0000890
8917. Using Python on non-UNIX platforms
892=====================================
893
Guido van Rossum91f60831994-02-15 15:52:27 +00008947.1. Q. Is there a Mac version of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000895
Guido van Rossum91f60831994-02-15 15:52:27 +0000896A. Yes. It is on most ftp sites carrying Python as python.sea.hqx --
897this is a self-extracting archive containing the application binary as
898well as the Lib modules.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000899
Guido van Rossum91f60831994-02-15 15:52:27 +00009007.2. Q. Is there a DOS version of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000901
Guido van Rossum91f60831994-02-15 15:52:27 +0000902A. Yes. More than one, actually: 16python.exe runs in standard DOS
903mode on 186 CPUs or higher; 32python.exe uses a DOS extender and only
904runs on a 386 or higher CPUs. Although 16python.exe does not pass the
905test set because test_grammar is too big for the parser, it actually
906has about 270 kbyte of allocatable heap space, which is sufficient for
907fairly large programs. 32python.exe is distributed as a tar file
908containing the required DOS extended and 387 emulator. Both are on
909most ftp sites carrying Python.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000910
Guido van Rossum91f60831994-02-15 15:52:27 +00009117.3. Q. Is there a Windows version of Python?
912
913A. Yes. Use qwpython.exe. The only problem with it: ^C
914unconditionally kills the entire program -- it does not raise
915KeyboardInterrupt. You can also run 16python.exe or 32python.exe in a
916"DOS box", but qwpython.exe appears to be slightly faster.
917
9187.4. Q. Is there a Windows NT version of Python?
919
920A. Yes. Use ntpython.exe. This is for Intel CPUs. If you want a
921Windows user interface, use qwpython.exe.
922
Guido van Rossum7ce61c11994-06-13 15:13:56 +00009237.5. Q. Is there an OS/2 version of Python?
924
925A. Yes. You can ftp it (from ftp.cwi.nl in pub/python, or from the
926mirror sites) as pyth_os2.zip. This contains both an executable and
927Makefiles for those fortunate enough to have a C compiler.
928
9297.6. Q. I have the PC version but it appears to be only a binary.
930Where's the library?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000931
932A. You still need to copy the files from the distribution directory
Guido van Rossum91f60831994-02-15 15:52:27 +0000933"python/Lib" to your system. If you don't have the full distribution,
Guido van Rossum3de27361994-07-25 14:19:33 +0000934you can get the file pythonlib<version>.tar.gz from most ftp sites
935carrying Python; this is a subset of the distribution containing just
936those file.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000937
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000938Once you have installed the library, you need to point sys.path to it.
939Assuming the library is in C:\misc\python\lib, the following commands
940will point your Python interpreter to it (note the doubled backslashes
941-- you can also use single forward slashes instead):
942
943 >>> import sys
944 >>> sys.path.insert(0, 'C:\\misc\\python\\lib')
945 >>>
946
947For a more permanent effect, set the environment variable PYTHONPATH,
948as follows (talking to a DOS prompt):
949
950 C> SET PYTHONPATH=C:\misc\python\lib
951
Guido van Rossum7ce61c11994-06-13 15:13:56 +00009527.7. Q. Where's the documentation for the Mac or PC version?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000953
954A. There isn't any. The documentation for the Unix version also
Guido van Rossum91f60831994-02-15 15:52:27 +0000955applies to the Mac and PC versions. Where applicable, differences
Guido van Rossuma7925f11994-01-26 10:20:16 +0000956are indicated in the text.
957
Guido van Rossum7ce61c11994-06-13 15:13:56 +00009587.8. Q. The Mac (PC) version doesn't seem to have any facilities for
Guido van Rossum91f60831994-02-15 15:52:27 +0000959creating or editing programs apart from entering it interactively, and
960there seems to be no way to save code that was entered interactively.
961How do I create a Python program on the Mac (PC)?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000962
Guido van Rossum91f60831994-02-15 15:52:27 +0000963A. Use an external editor. On the Mac, I am quite happy with the Desk
964Accessory called Sigma Edit; this doesn't require Multifinder or
965System 7. I work like this: start the interpreter; edit a module file
966using Sigma Edit; import and test it in the interpreter; edit again in
967Sigma Edit; then use the built-in function reload() to re-read the
968imported module; etc.
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000969
970Regarding the same question for the PC, Kurt Wm. Hemr writes: "While
971anyone with a pulse could certainly figure out how to do the same on
972MS-Windows, I would recommend the NotGNU Emacs clone for MS-Windows.
973Not only can you easily resave and "reload()" from Python after making
974changes, but since WinNot auto-copies to the clipboard any text you
975select, you can simply select the entire procedure (function) which
976you changed in WinNot, switch to QWPython, and shift-ins to reenter
977the changed program unit."