blob: 31c76bd11cae335be7792bb4b80446acbb98745c [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 Rossumb34e8aa1994-09-23 14:20:38 +00009Version: 1.14
10Last-modified: 23 September 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
Guido van Rossumb34e8aa1994-09-23 14:20:38 +000044Skip Montanaro <skip@automatrix.com> maintains an HTML version of this
45FAQ. The URL is "http://www.automatrix.com/~skip/python-faq.html".
46
Guido van Rossuma7925f11994-01-26 10:20:16 +000047This FAQ is divided in the following chapters:
48
49 1. General information and availability
50 2. Python in the real world
51 3. Building Python
52 4. Programming in Python
53 5. Extending Python
54 6. Python's design
55 7. Using Python on non-UNIX platforms
56
57To find the start of a particular chapter, search for the chapter number
58followed by a dot and a space at the beginning of a line (e.g. to
59find chapter 4 in vi, type /^4\. /).
60
61Here's an overview of the questions per chapter:
62
63 1. General information and availability
64 1.1. Q. What is Python?
65 1.2. Q. Why is it called Python?
66 1.3. Q. How do I obtain a copy of the Python source?
67 1.4. Q. How do I get documentation on Python?
Guido van Rossumc50158e1994-05-31 09:18:50 +000068 1.5. Q. Are there other ftp sites that mirror the Python distribution?
69 1.6. Q. Is there a newsgroup or mailing list devoted to Python?
70 1.7. Q. Is there a book on Python, or will there be one out soon?
71 1.8. Q. Are there any published articles about Python that I can quote?
72 1.9. Q. How does the Python version numbering scheme work?
73 1.10. Q. Are there other ftp sites that carry Python related material?
Guido van Rossum7ce61c11994-06-13 15:13:56 +000074 1.11. Q. Are there copyright restrictions on the use of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +000075
76 2. Python in the real world
77 2.1. Q. How many people are using Python?
78 2.2. Q. Have any significant projects been done in Python?
79 2.3. Q. Are there any commercial projects going on using Python?
Guido van Rossum95f61a71994-01-26 17:23:37 +000080 2.4. Q. How stable is Python?
Guido van Rossumb34e8aa1994-09-23 14:20:38 +000081 2.5. Q. When will the next version be released?
82 2.6. Q. What new developments are expected for Python in the future?
83 2.7. Q. Is it reasonable to propose incompatible changes to Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +000084
85 3. Building Python
Guido van Rossum91f60831994-02-15 15:52:27 +000086 3.1. Q. Is there a test set?
87 3.2. Q. When running the test set, I get complaints about floating point
Guido van Rossuma7925f11994-01-26 10:20:16 +000088 operations, but when playing with floating point operations I cannot
89 find anything wrong with them.
Guido van Rossum91f60831994-02-15 15:52:27 +000090 3.3. Q. Link errors building Python with STDWIN on SGI IRIX.
91 3.4. Q. Link errors after rerunning the configure script.
92 3.5. Q. The python interpreter complains about options passed to a
Guido van Rossum24349991994-02-02 14:12:45 +000093 script (after the script name).
Guido van Rossum91f60831994-02-15 15:52:27 +000094 3.6. Q. When building on the SGI, make tries to run python to create
Guido van Rossum5333c5d1994-04-11 11:06:22 +000095 glmodule.c, but python hasn't been built or installed yet.
Guido van Rossum3de27361994-07-25 14:19:33 +000096 3.7. Q. Python built with gcc for the DEC Alpha doesn't work.
Guido van Rossumb34e8aa1994-09-23 14:20:38 +000097 3.8. Q. I use VPATH but some targets are built in the source directory.
98 3.9. Q. Trouble building or linking with the GNU readline library.
99 3.10. Q. Trouble building Python on Linux.
100 3.11. Q. Other trouble building Python on platform X.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000101
102 4. Programming in Python
Guido van Rossum24349991994-02-02 14:12:45 +0000103 4.1. Q. Is there a source code level debugger with breakpoints, step,
104 etc.?
105 4.2. Q. Can I create an object class with some methods implemented in
Guido van Rossuma7925f11994-01-26 10:20:16 +0000106 C and others in Python (e.g. through inheritance)? (Also phrased as:
107 Can I use a built-in type as base class?)
Guido van Rossum24349991994-02-02 14:12:45 +0000108 4.3. Q. Is there a curses/termcap package for Python?
109 4.4. Q. Is there an equivalent to C's onexit() in Python?
110 4.5. Q. When I define a function nested inside another function, the
Guido van Rossuma7925f11994-01-26 10:20:16 +0000111 nested function seemingly can't access the local variables of the
112 outer function. What is going on? How do I pass local data to a
113 nested function?
Guido van Rossum24349991994-02-02 14:12:45 +0000114 4.6. Q. How do I iterate over a sequence in reverse order?
115 4.7. Q. My program is too slow. How do I speed it up?
116 4.8. Q. When I have imported a module, then edit it, and import it
Guido van Rossuma7925f11994-01-26 10:20:16 +0000117 again (into the same Python process), the changes don't seem to take
118 place. What is going on?
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000119 4.9. Q. How do I find the current module name?
120 4.10. Q. I have a module in which I want to execute some extra code when it
121 is run as a script. How do I find out whether I am running as a
122 script?
123 4.11. Q. I try to run a program from the Demo directory but it fails with
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000124 ImportError: No module named ...; what gives?
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000125 4.12. Q. I have successfully built Python with STDWIN but it can't find some
126 modules (e.g. stdwinevents).
127 4.13. Q. What GUI toolkits exist for Python?
128 4.14. Q. Are there any interfaces to commercial database in Python?
129 4.15. Q. Is it possible to write obfuscated one-liners in Python?
130 4.16. Q. Is there an equivalent of C's "?:" ternary operator?
131 4.17. Q. My class defines __del__ but it is not called when I delete the
132 object.
133 4.18. Q. How do I change the shell environment for programs called using
134 os.popen() or os.system()? Changing os.environ doesn't work.
135 4.19. Q. What is a class?
136 4.20. Q. What is a method?
137 4.21. Q. What is self?
138 4.22. Q. What is a unbound method?
139 4.23. Q. How do I call a method defined in a base class from a derived class
140 that overrides it?
141 4.24. Q. How do I call a method from a base class without using the name of
142 the base class?
143 4.25. Q. How can I organize my code to make it easier to change the base
144 class?
145 4.26. Q. How can I find the methods or attributes of an object?
146 4.27. an't seem to use os.read() on a pipe created with os.popen().
Guido van Rossuma7925f11994-01-26 10:20:16 +0000147
148 5. Extending Python
149 5.1. Q. Can I create my own functions in C?
150 5.2. Q. Can I create my own functions in C++?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000151 5.3. Q. How can I execute arbitrary Python statements from C?
152 5.4. Q. How can I evaluate an arbitrary Python expression from C?
153 5.5. Q. How do I extract C values from a Python object?
154 5.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000155 5.7. Q. What happened to mktuple(), featuring in an example in the
156 Extensions manual?
157 5.8. Q. How do I call an object's method from C?
158 5.9. Q. How do I catch the output from print_error()?
159 5.10. Q. How do I access a module written in Python from C?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000160
161 6. Python's design
162 6.1. Q. Why isn't there a generic copying operation for objects in
163 Python?
164 6.2. Q. Why isn't there a generic way to implement persistent objects
165 in Python? (Persistent == automatically saved to and restored from
166 disk.)
167 6.3. Q. Why isn't there a switch or case statement in Python?
Guido van Rossumc50158e1994-05-31 09:18:50 +0000168 6.4. Q. Why does Python use indentation for grouping of statements?
Guido van Rossum3de27361994-07-25 14:19:33 +0000169 6.5. Q. Why are Python strings immutable?
170 6.6. Q. Why don't strings have methods like index() or sort(), like
171 lists?
172 6.7. Q. Why does Python use methods for some functionality
173 (e.g. list.index()) but functions for other (e.g. len(list))?
174 6.8. Q. Why can't I derive a class from built-in types (e.g. lists or
175 files)?
176 6.9. Q. Why must 'self' be declared and used explicitly in method
177 definitions and calls?
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000178 6.10. 't you emulate threads in the interpreter instead of relying on
179 an OS-specific thread implementation?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000180
181 7. Using Python on non-UNIX platforms
Guido van Rossum91f60831994-02-15 15:52:27 +0000182 7.1. Q. Is there a Mac version of Python?
183 7.2. Q. Is there a DOS version of Python?
184 7.3. Q. Is there a Windows version of Python?
185 7.4. Q. Is there a Windows NT version of Python?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000186 7.5. Q. Is there an OS/2 version of Python?
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000187 7.6. Q. Is there a VMS version of Python?
188 7.7. Q. What about IBM mainframes, or other esoteric non-UNIX
189 platforms?
190 7.8. Q. Where are the source or Makefiles for the non-UNIX versions?
191 7.9. Q. What is the status and support for the non-UNIX versions?
192 7.10. Q. I have the PC version but it appears to be only a binary.
193 Where's the library?
194 7.11. Q. Where's the documentation for the Mac or PC version?
195 7.12. Q. The Mac (PC) version doesn't seem to have any facilities for
196 creating or editing programs apart from entering it interactively, and
197 there seems to be no way to save code that was entered interactively.
198 How do I create a Python program on the Mac (PC)?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000199
200To find a particular question, search for the question number followed
201by a dot, a space, and a Q at the beginning of a line (e.g. to find
202question 4.2 in vi, type /^4\.2\. Q/).
203
204
2051. General information and availability
206=======================================
207
2081.1. Q. What is Python?
209
210A. Python is an interpreted, interactive, object-oriented programming
211language. It incorporates modules, exceptions, dynamic typing, very
212high level dynamic data types, and classes. Python combines
213remarkable power with very clear syntax. It has interfaces to many
214system calls and libraries, as well as to various window systems, and
215is extensible in C or C++. It is also usable as an extension language
216for applications that need a programmable interface. Finally, Python
217is portable: it runs on many brands of UNIX, on the Mac, and on
218MS-DOS.
219
220To find out more, the best thing to do is to start reading the
221tutorial from the documentation set (see a few questions further
222down).
223
2241.2. Q. Why is it called Python?
225
226A. Apart from being a computer wizard, I'm also a fan of "Monty
227Python's Flying Circus" (a BBC comedy series from the seventies, in
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000228the -- unlikely -- case you didn't know). It occurred to me one day
229that I needed a name that was short, unique, and slightly mysterious.
230And I happened to be reading some scripts from the series at the
231time... So then I decided to call my language Python. But Python is
232not a joke. And don't you associate it with dangerous reptiles
233either!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000234
2351.3. Q. How do I obtain a copy of the Python source?
236
237A. The latest Python source distribution is always available by
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000238anonymous ftp from ftp.cwi.nl [192.16.191.128] in the directory
Guido van Rossum44b4cb11994-05-04 13:28:51 +0000239/pub/python, with filename python<version>.tar.gz. (Old versions may
240have an extension of .Z, indicating use of "compress" compression.)
241It is a gzip'ed tar file containing the complete C source, LaTeX
242documentation, Python library modules, example programs, and several
243useful pieces of freely distributable software. This will compile and
Guido van Rossum3de27361994-07-25 14:19:33 +0000244run out of the box on most UNIX platforms. (See section 7 for
245non-UNIX information.)
Guido van Rossuma7925f11994-01-26 10:20:16 +0000246
2471.4. Q. How do I get documentation on Python?
248
249A. The latest Python documentation set is always available by
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000250anonymous ftp from ftp.cwi.nl [192.16.191.128] in the directory
Guido van Rossum44b4cb11994-05-04 13:28:51 +0000251/pub/python, with filename pythondoc-ps<version>.tar.gz. It is a
252gzip'ed tar file containing PostScript files of the reference manual,
Guido van Rossum3de27361994-07-25 14:19:33 +0000253the library manual, and the tutorial. Note that the library manual is
254the most important one of the set, as much of Python's power stems
255from the standard or built-in types, functions and modules, all of
256which are described here. PostScript for a high-level description of
257Python is in the file nluug-paper.ps.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000258
Guido van Rossumc50158e1994-05-31 09:18:50 +00002591.5. Q. Are there other ftp sites that mirror the Python distribution?
260
261A. The following sites keep mirrors of the Python distribution:
Guido van Rossuma7925f11994-01-26 10:20:16 +0000262
263Site IP address Directory
264
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000265gatekeeper.dec.com 16.1.0.2 /pub/plan/python
Guido van Rossuma7925f11994-01-26 10:20:16 +0000266ftp.uu.net 192.48.96.9 /languages/python
267ftp.wustl.edu 128.252.135.4 /graphics/graphics/sgi-stuff/python
Guido van Rossumc50158e1994-05-31 09:18:50 +0000268ftp.funet.fi 128.214.6.100 /pub/languages/python
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000269ftp.fu-berlin.de 130.133.1.18 /unix/languages/python (*python* only)
Guido van Rossumc50158e1994-05-31 09:18:50 +0000270ftp.sunet.se 130.238.127.3 /pub/lang/python
Guido van Rossumea2c6f71994-07-14 12:35:14 +0000271unix.hensa.ac.uk 129.12.43.16 /uunet/languages/python
Guido van Rossuma7925f11994-01-26 10:20:16 +0000272
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000273Or try archie on e.g. python1.0 to locate the nearest copy of that
274version...
Guido van Rossuma7925f11994-01-26 10:20:16 +0000275
Guido van Rossumc50158e1994-05-31 09:18:50 +00002761.6. Q. Is there a newsgroup or mailing list devoted to Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000277
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000278A. There is a newsgroup, comp.lang.python, and a mailing list. The
279newsgroup and mailing list are gatewayed into each other -- if you can
280read news it is not necessary to subscribe to the mailing list. Send
281e-mail to python-list-request@cwi.nl to (un)subscribe to the mailing
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000282list. Once you're on, send e-mail tp python-list@cwi.nl to send mail
283to the entire mailing list and newsgroup.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000284
Guido van Rossumc50158e1994-05-31 09:18:50 +00002851.7. Q. Is there a book on Python, or will there be one out soon?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000286
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000287A. Unfortunately, not yet. Mark Lutz and I are planning to write one,
288but we are still a in very preliminary stage. If you would like to
289beat us at it and get rich from book royalties, go ahead!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000290
Guido van Rossumc50158e1994-05-31 09:18:50 +00002911.8. Q. Are there any published articles about Python that I can quote?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000292
293A. So far the only refereed and published article that describes
294Python in some detail is:
295
296 Guido van Rossum and Jelke de Boer, "Interactively Testing Remote
297 Servers Using the Python Programming Language", CWI Quarterly, Volume
298 4, Issue 4 (December 1991), Amsterdam, pp 283-303.
299
300LaTeX source for this paper is available as part of the Python source
301distribution.
302
303A more recent high-level description of Python is:
304
305 Guido van Rossum, "An Introduction to Python for UNIX/C
306 Programmers", in the proceedings of the NLUUG najaarsconferentie
307 1993 (dutch UNIX users group meeting november 1993).
308
309PostScript for this paper and for the slides used for the accompanying
310presentation can be found in the ftp directory mentioned a few
311questions earlier, with filenames nluug-paper.ps and nluug-slides.ps,
312respectively.
313
Guido van Rossumc50158e1994-05-31 09:18:50 +00003141.9. Q. How does the Python version numbering scheme work?
Guido van Rossum95f61a71994-01-26 17:23:37 +0000315
316A. Python versions are numbered A.B.C. A is the major version number
317-- it is only incremented for major changes in functionality or source
318structure. B is the minor version number, incremented for less
319earth-shattering changes to a release. C is the patchlevel -- it is
320incremented for each new release. Note that in the past, patches have
321added significant changes; in fact the changeover from 0.9.9 to 1.0.0
322was the first time that either A or B changed!
323
Guido van Rossumc50158e1994-05-31 09:18:50 +00003241.10. Q. Are there other ftp sites that carry Python related material?
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000325
326A. An interesting ftp site for Python users is ftp.markv.com
327(192.122.251.1); the directory pub/python contains a growing
328collection of interesting Python scripts. To submit a script for
329inclusion, place it together with a readme file (with extension
330.readme) in the publicly writable directory /incoming/python. This
331service is maintained by Lance Ellinghouse <lance@markv.com>.
332
Guido van Rossum7ce61c11994-06-13 15:13:56 +00003331.11. Q. Are there copyright restrictions on the use of Python?
334
335A. Hardly. You can do anything you want with the source, as long as
336you leave the copyrights in, display those copyrights in any
337documentation about Python that you produce, don't use the author's
338institute's name in publicity without prior written permission, and
339don't hold them responsible for anything (read the actual copyright
340for a precise legal wording).
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000341
Guido van Rossuma7925f11994-01-26 10:20:16 +0000342
3432. Python in the real world
344===========================
345
3462.1. Q. How many people are using Python?
347
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000348A. I don't know, but the maximum number of simultaneous subscriptions
349to the Python mailing list before it was gatewayed into the newsgroup
350was about 180 (several of which were local redistribution lists). I
351believe that many active Python users don't bother to subscribe to the
352list, and now that there's a newsgroup the mailing list subscription
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000353is even less meaningful. I see new names on the newsgroup all the
354time and my best guess is that there are currently at least several
355thousands of users.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000356
3572.2. Q. Have any significant projects been done in Python?
358
359A. Here at CWI (the home of Python), we have written a 20,000 line
360authoring environment for transportable hypermedia presentations, a
Guido van Rossum5333c5d1994-04-11 11:06:22 +00003615,000 line multimedia teleconferencing tool, as well as many many
362smaller programs.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000363
364The University of Virginia uses Python to control a virtual reality
365engine. Contact: Matt Conway <conway@virginia.edu>.
366
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000367If you have done a significant project in Python that you'd like to be
368included in the list above, send me email!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000369
3702.3. Q. Are there any commercial projects going on using Python?
371
372A. Several companies have revealed to me that they are planning or
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000373considering to use Python in a future product.
374
375The furthest is Sunrise Software, who already have a product out using
376Python -- they use Python for a GUI management application and an SNMP
377network manangement application. Contact: <info@sunrise.com>.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000378
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000379Infoseek is using python to implement their commercial WWW information
380retrieval service. Contact: <info@infoseek.com>.
381
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000382Michael Powers of daVinci Time & Space is "writing tons-o-python for
383interactive television entertainment." Contact: <powers@dvts.com>.
384
Guido van Rossuma7925f11994-01-26 10:20:16 +0000385Individuals at many other companies are using Python for
386internal development (witness their contributions to the Python
Guido van Rossum5333c5d1994-04-11 11:06:22 +0000387mailing list or newsgroup).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000388
389Python has also been elected as an extension language by MADE, a
390consortium supported by the European Committee's ESPRIT program and
391consisting of Bull, CWI and some other European companies. Contact:
392Ivan Herman <ivan@cwi.nl>.
393
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000394If you'd like to be included in the list above, send me email!
395
Guido van Rossum95f61a71994-01-26 17:23:37 +00003962.4. Q. How stable is Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000397
Guido van Rossum3de27361994-07-25 14:19:33 +0000398A. Very stable. While the current version number would suggest it is
399in the early stages of development, in fact new, stable releases
400(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 +0000401months for the past four years.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000402
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00004032.5. Q. When will the next version be released?
404
405A. I am planning to release 1.1 before October 15. It will contain
406tons of changes, including (again) improved portability, especially
407better support for DOS, Windows, Windows NT an the Macintosh. A few
408modules will have been converted to the new naming scheme. A working
409signal module will be present.
410
4112.6. Q. What new developments are expected for Python in the future?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000412
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000413A. A proposal is being worked out to change the semantics of operator
414overloading (__add__, __mul__ etc.) to make them more useful for
415implementing types that don't resemble numbers. Additions will be
416__call__ (to call an instance as if it were a function) and __eq__,
417_lt__ etc. (to override individual comparisons). A (new) pthreads
418interface has been submitted which will be integrated in the next
419release. The X11/Motif interface will be improved. There are ideas
420about built-in help using strings placed into function objects, and
421possibly a switch statement.
422
423There will be better ports to the Mac, DOS, Windows, Windows NT, and
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000424OS/2. The Windows ports will support dynamically loaded modules using
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000425DLLs.
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000426
427Also planned is improved support for embedding Python in other
428applications, e.g. by renaming most global symbols to have a "Py"
429prefix and providing more documentation and threading support.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000430
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00004312.7. Q. Is it reasonable to propose incompatible changes to Python?
Guido van Rossum3de27361994-07-25 14:19:33 +0000432
433A. In general, no. There are already millions of lines of Python code
434around the world, so any changes in the language that invalidates more
435than a very small fraction of existing programs has to be frowned
436upon. Even if you can provide a conversion program, there still is
437the problem of updating all documentation. Providing a gradual
438upgrade path is the only way if a feature has to be changed.
439
Guido van Rossuma7925f11994-01-26 10:20:16 +0000440
4413. Building Python
442==================
443
Guido van Rossum91f60831994-02-15 15:52:27 +00004443.1. Q. Is there a test set?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000445
446A. Yes, simply do "import testall" (or "import autotest" if you aren't
447interested in the output). The standard modules whose name begins
448with "test" together comprise the test. The test set doesn't test
449*all* features of Python but it goes a long way to confirm that a new
450port is actually working. The Makefile contains an entry "make test"
451which runs the autotest module.
452
Guido van Rossum91f60831994-02-15 15:52:27 +00004533.2. Q. When running the test set, I get complaints about floating point
Guido van Rossuma7925f11994-01-26 10:20:16 +0000454operations, but when playing with floating point operations I cannot
455find anything wrong with them.
456
457A. The test set makes occasional unwarranted assumptions about the
458semantics of C floating point operations. Until someone donates a
459better floating point test set, you will have to comment out the
460offending floating point tests and execute similar tests manually.
461
Guido van Rossum91f60831994-02-15 15:52:27 +00004623.3. Q. Link errors building Python with STDWIN on SGI IRIX.
Guido van Rossum24349991994-02-02 14:12:45 +0000463
464A. Rebuild STDWIN, specifying "CC=cc -cckr" in the Makefile.
465
Guido van Rossum91f60831994-02-15 15:52:27 +00004663.4. Q. Link errors after rerunning the configure script.
Guido van Rossum24349991994-02-02 14:12:45 +0000467
468A. It is generally necessary to run "make clean" after a configuration
469change.
470
Guido van Rossum91f60831994-02-15 15:52:27 +00004713.5. Q. The python interpreter complains about options passed to a
Guido van Rossum24349991994-02-02 14:12:45 +0000472script (after the script name).
473
474A. You are probably linking with GNU getopt, e.g. through -liberty.
Guido van Rossumf8c76d01994-08-17 12:19:53 +0000475Don't. The reason for the complaint is that GNU getopt, unlike System
476V getopt and other getopt implementations, doesn't consider a
477non-option to be the end of the option list. A quick (and compatible)
478fix for scripts is to add "--" to the interpreter, like this:
479
480 #! /usr/local/bin/python --
481
482You can also use this interactively:
483
484 python -- script.py [options]
Guido van Rossum24349991994-02-02 14:12:45 +0000485
Guido van Rossum91f60831994-02-15 15:52:27 +00004863.6. Q. When building on the SGI, make tries to run python to create
Guido van Rossum24349991994-02-02 14:12:45 +0000487glmodule.c, but python hasn't been built or installed yet.
488
489A. Comment out the line mentioning glmodule.c in Setup and build a
490python without gl first; install it or make sure it is in your $PATH,
491then edit the Setup file again to turn on the gl module, and make
492again. You don't need to do "make clean"; you do need to run "make
493Makefile" in the Modules subdirectory (or just run "make" at the
494toplevel).
495
Guido van Rossum3de27361994-07-25 14:19:33 +00004963.7. Q. Python built with gcc for the DEC Alpha doesn't work.
497
498People have reported problems with both gcc 2.5.8 and 2.6.0. The DEC
499OSF/1 cc compiler does not have these problems so it's probably gcc's
500fault. One person reported that the problem went away when using -g
501instead of -O so this may be an option if you insist on using gcc. If
502someone tracks it down more completely I'd like to hear about it!
503
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00005043.8. Q. I use VPATH but some targets are built in the source directory.
505
506A. On some systems (e.g. Sun), if the target already exists in the
507source directory, it is created there instead of in the build
508directory. This is usually because you have previously built without
509VPATH. Try running "make clobber" in the source directory.
510
5113.9. Q. Trouble building or linking with the GNU readline library.
512
513A. Consider using readline 2.0. From the Python 1.1 README:
514
515- You can use the GNU readline library to improve the interactive user
516interface: this gives you line editing and command history when
517calling python interactively. You need to configure build the GNU
518readline library before running the configure script. Its sources are
519no longer distributed with Python; you can ftp them from any GNU
520mirror site, or from its home site:
521ftp://slc2.ins.cwru.edu/pub/dist/readline-2.0.tar.gz (or a higher
522version number -- using version 1.x is not recommended). Pass the
523Python configure script the option --with-readline=DIRECTORY where
524DIRECTORY is the absolute pathname of the directory where you've built
525the readline library. Some hints on building and using the readline
526library:
527
528- On SGI IRIX 5, you may have to add the following
529to rldefs.h:
530
531#ifndef sigmask
532#define sigmask(sig) (1L << ((sig)-1))
533#endif
534
535- On most systems, you will have to add #include "rldefs.h" to the
536top of several source files, and if you use the VPATH feature, you
537will have to add dependencies of the form foo.o: foo.c to the
538Makefile for several values of foo.
539
540- The readline library requires use of the termcap library. A
541known problem with this is that it contains entry points which
542cause conflicts with the STDWIN and SGI GL libraries. The stdwin
543conflict can be solved (and will be, in the next release of
544stdwin) by adding a line saying '#define werase w_erase' to the
545stdwin.h file (in the stdwin distribution, subdirectory H). The
546GL conflict has been solved in the Python configure script by a
547hack that forces use of the static version of the termcap library.
548
549- Check the newsgroup gnu.bash.bugs for specific problems with the
550readline library (I don't get this group here but I've been told
551that it is the place for readline bugs.)
552
5533.10. Q. Trouble building Python on Linux.
554
555A. There shouldn't be any -- I've seen several complaints but more
556reports on successful "out-of-the-box" ports on Linux. The standard
557configure script runs just fine on Linux.
558
5593.11. Q. Other trouble building Python on platform X.
Guido van Rossum95f61a71994-01-26 17:23:37 +0000560
561A. Please email the details to <guido@cwi.nl> and I'll look into it.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000562
563
5644. Programming in Python
565========================
566
Guido van Rossum24349991994-02-02 14:12:45 +00005674.1. Q. Is there a source code level debugger with breakpoints, step,
568etc.?
569
570A. Yes. Check out module pdb; pdb.help() prints the documentation (or
571you can read it as Lib/pdb.doc). If you use the STDWIN option,
572there's also a windowing interface, wdb. You can write your own
573debugger by using the code for pdb or wdb as an example.
574
5754.2. Q. Can I create an object class with some methods implemented in
Guido van Rossuma7925f11994-01-26 10:20:16 +0000576C and others in Python (e.g. through inheritance)? (Also phrased as:
577Can I use a built-in type as base class?)
578
579A. No, but you can easily create a Python class which serves as a
580wrapper around a built-in object, e.g. (for dictionaries):
581
582 # A user-defined class behaving almost identical
583 # to a built-in dictionary.
584 class UserDict:
585 def __init__(self): self.data = {}
586 def __repr__(self): return repr(self.data)
587 def __cmp__(self, dict):
588 if type(dict) == type(self.data):
589 return cmp(self.data, dict)
590 else:
591 return cmp(self.data, dict.data)
592 def __len__(self): return len(self.data)
593 def __getitem__(self, key): return self.data[key]
594 def __setitem__(self, key, item): self.data[key] = item
595 def __delitem__(self, key): del self.data[key]
596 def keys(self): return self.data.keys()
597 def items(self): return self.data.items()
598 def values(self): return self.data.values()
599 def has_key(self, key): return self.data.has_key(key)
600
Guido van Rossum24349991994-02-02 14:12:45 +00006014.3. Q. Is there a curses/termcap package for Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000602
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000603A. Yes -- Lance Ellinghouse has written a module that interfaces to
604System V's "ncurses". If you know a little curses and some Python,
605it's straightforward to use.
606
607You could also consider using the "alfa" (== character cell) version
608of STDWIN. (STDWIN == Standard Windows, a portable windowing system
609interface by the same author, URL: "ftp://ftp.cwi.nl/pub/stdwin".) This
610will also prepare your program for porting to windowing environments
611such as X11 or the Macintosh.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000612
Guido van Rossum24349991994-02-02 14:12:45 +00006134.4. Q. Is there an equivalent to C's onexit() in Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000614
615A. Yes, if you import sys and assign a function to sys.exitfunc, it
616will be called when your program exits, is killed by an unhandled
617exception, or (on UNIX) receives a SIGHUP or SIGTERM signal.
618
Guido van Rossum24349991994-02-02 14:12:45 +00006194.5. Q. When I define a function nested inside another function, the
Guido van Rossuma7925f11994-01-26 10:20:16 +0000620nested function seemingly can't access the local variables of the
621outer function. What is going on? How do I pass local data to a
622nested function?
623
624A. Python does not have arbitrarily nested scopes. When you need to
625create a function that needs to access some data which you have
626available locally, create a new class to hold the data and return a
627method of an instance of that class, e.g.:
628
629 class MultiplierClass:
630 def __init__(self, factor):
631 self.factor = factor
632 def multiplier(self, argument):
633 return argument * self.factor
634
635 def generate_multiplier(factor):
636 return MultiplierClass(factor).multiplier
637
638 twice = generate_multiplier(2)
639 print twice(10)
640 # Output: 20
641
Guido van Rossum24349991994-02-02 14:12:45 +00006424.6. Q. How do I iterate over a sequence in reverse order?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000643
644A. If it is a list, the fastest solution is
645
646 list.reverse()
647 try:
648 for x in list:
649 "do something with x"
650 finally:
651 list.reverse()
652
653This has the disadvantage that while you are in the loop, the list
654is temporarily reversed. If you don't like this, you can make a copy.
655This appears expensive but is actually faster than other solutions:
656
657 rev = list[:]
658 rev.reverse()
659 for x in rev:
660 <do something with x>
661
662If it isn't a list, a more general but slower solution is:
663
664 i = len(list)
665 while i > 0:
666 i = i-1
667 x = list[i]
668 <do something with x>
669
670A more elegant solution, is to define a class which acts as a sequence
671and yields the elements in reverse order (solution due to Steve
672Majewski):
673
674 class Rev:
675 def __init__(self, seq):
676 self.forw = seq
677 def __len__(self):
678 return len(self.forw)
679 def __getitem__(self, i):
680 return self.forw[-(i + 1)]
681
682You can now simply write:
683
684 for x in Rev(list):
685 <do something with x>
686
687Unfortunately, this solution is slowest of all, due the the method
688call overhead...
689
Guido van Rossum24349991994-02-02 14:12:45 +00006904.7. Q. My program is too slow. How do I speed it up?
Guido van Rossuma7925f11994-01-26 10:20:16 +0000691
692A. That's a tough one, in general. There are many tricks to speed up
693Python code; I would consider rewriting parts in C only as a last
694resort. One thing to notice is that function and (especially) method
695calls are rather expensive; if you have designed a purely OO interface
696with lots of tiny functions that don't do much more than get or set an
697instance variable or call another method, you may consider using a
698more direct way, e.g. directly accessing instance variables. Also see
699the standard module "profile" (described in the file
700"python/lib/profile.doc") which makes it possible to find out where
701your program is spending most of its time (if you have some patience
702-- the profiling itself can slow your program down by an order of
703magnitude).
704
Guido van Rossum24349991994-02-02 14:12:45 +00007054.8. Q. When I have imported a module, then edit it, and import it
Guido van Rossuma7925f11994-01-26 10:20:16 +0000706again (into the same Python process), the changes don't seem to take
707place. What is going on?
708
709A. For efficiency reasons, Python only reads the module file on the
710first time a module is imported (otherwise a program consisting of
711many modules, each of which imports the same basic module, would read
712the basic module over and over again). To force a changed module
713being read again, do this:
714
715 import modname
716 reload(modname)
717
718Warning: this technique is not 100% fool-proof. In particular,
719modules containing statements like
720
721 from modname import some_objects
722
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000723will continue to work with the old version of the imported objects.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000724
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00007254.9. Q. How do I find the current module name?
Guido van Rossum24349991994-02-02 14:12:45 +0000726
727A. A module can find out its own module name by alooking at the
728(predefined) global variable __name__. If this has the value
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000729'__main__' you are running as a script.
730
7314.10. Q. I have a module in which I want to execute some extra code when it
732is run as a script. How do I find out whether I am running as a
733script?
734
735A. See the previous question. E.g. if you put the following on the
736last line of your module, main() is called only when your module is
737running as a script:
Guido van Rossum24349991994-02-02 14:12:45 +0000738
739 if __name__ == '__main__': main()
740
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00007414.11. Q. I try to run a program from the Demo directory but it fails with
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000742ImportError: No module named ...; what gives?
743
744A. This is probably an optional module which hasn't been configured on
745your system. This especially happens with modules like "stdwin",
746"gl", "Xt" or "Xm". For stdwin and many other modules, see
747Modules/Setup.in for info on how to add these modules to your Python,
748if it is possible at all. Sometimes you will have to ftp and build
749another package first (e.g. stdwin). Sometimes the module only works
750on specific platforms (e.g. gl only works on SGI machines). For
751X-related modules (Xt and Xm) you will have to do more work: they are
752currently not part of the standard Python distribution. You will have
753to ftp the file "extensions.tar.gz" file from a Python ftp repository
754(e.g. ftp.cwi.nl) and follow the instructions there. Note: the X
755related modules are still somewhat flakey, so don't try this unless
756you know a bit or two about building X applications on your platform.
757
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00007584.12. Q. I have successfully built Python with STDWIN but it can't find some
759modules (e.g. stdwinevents).
760
761A. There's a subdirectory of the library directory named 'stdwin'
762which should be in the default module search path. There's a line in
763Modules/Setup(.in) that you have to enable for this purpose --
764unfortuunately in the latest release it's not near the other
765STDWIN-related lines so it's easy to miss it.
766
7674.13. Q. What GUI toolkits exist for Python?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000768
769A. Depending on what platform(s) you are aiming at, there are several.
770
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000771- There's a neat object-oriented interface to the Tcl/Tk widget set,
772called Tkinter. You can ftp it from ftp.cwi.nl as
773pub/python/tkinter.tar.gz. This is probably the easiest to install
774and use, and the most complete widget set.
775
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000776- The standard Python distribution comes with an interface to STDWIN,
777a platform-independent low-level windowing interface (you have to ftp
778the source for stdwin separately, e.g. from ftp.cwi.nl in pub/stdwin
779or gatekeeper.dec.com in pub/misc/stdwin). STDWIN runs under X11 or
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000780the Mac; a Windows port has been attempted but I can't seem to get it
781working. Note that STDWIN is really not powerful enough to implement
782a modern GUI (no widgets, etc.) and that I don't have the time to
783maintain or extend it, so you may be better off using Tkinter or the
784Motif interface, unless you require portability to the Mac (which is
785also offered by SUIT, by the way -- see below).
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000786
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000787- For SGI IRIX only, there's an interface to the complete GL (Graphics
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000788Library -- low level but very good 3D capabilities) as well as to
789FORMS (a buttons-and-sliders-etc package built on top of GL by Mark
790Overmars -- ftp'able from ftp.cs.ruu.nl in pub/SGI/FORMS).
791
792- There's an interface to X11, including the Athena and Motif widget
793sets (and a few individual widgets, like Mosaic's HTML widget and
794SGI's GL widget) in the Extensions set, which is separately ftp'able
795from ftp.cwi.nl as pub/python/extensions.tar.gz.
796
797- There's an interface to SUIT, the U of Virginia's Simple User
798Interface Toolkit; it can be ftp'ed from uvacs.cs.virginia.edu as
799pub/suit/python/SUIT_python.tar.Z. A PC binary of Python 1.0.2
800compiled with DJGPP and with SUIT support built-in has been made
801available by Antonio Costa on ftp site asterix.inescn.pt, directory
802pub/PC/python, file pyt102su.exe (a self-extracting archive).
803
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000804- There's an interface to WAFE, a Tcl interface to the X11 Motif and
805Athena widget sets. Last I heard about it it was included in the
806WAFE 1.0 prerelease, ftp'able from ftp.wu-wien.ac.at as
807pub/src/X11/wafe/wafe-1.0.tar.gz-prerelease.
808
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00008094.14. Q. Are there any interfaces to commercial database in Python?
Guido van Rossum7ce61c11994-06-13 15:13:56 +0000810
811A. There's an interface to SYBASE by John Redford
812<jredford@lehman.com>.
813
814There's also an interface to metalbase by Lance Ellinghouse
815<lance@markv.com>.
816
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000817Anthony Baxter <anthony.baxter@aaii.oz.au> has written an interface to
818mSQL (mini-SQL). Ftp it from ftp.cwi.nl:/pub/python/PymSQL.tar.gz.
819
8204.15. Q. Is it possible to write obfuscated one-liners in Python?
Guido van Rossumc24da7c1994-09-23 14:08:41 +0000821
822A. Yes. See the following three examples, due to Ulf Bartelt:
823
824# Primes < 1000
825print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,\
826map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000)))
827
828# First 10 Fibonacci numbers
829print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),\
830range(10))
831
832# Mandelbrot set
833print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,\
834Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,\
835Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,\
836i=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\
837>=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(\
83864+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy\
839))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)
840# \___ ___/ \___ ___/ | | |__ lines on screen
841# V V | |______ columns on screen
842# | | |__________ maximum of "iterations"
843# | |_________________ range on y axis
844# |____________________________ range on x axis
845
846Don't try this at home, kids!
847
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00008484.16. Q. Is there an equivalent of C's "?:" ternary operator?
Guido van Rossumc24da7c1994-09-23 14:08:41 +0000849
Guido van Rossumb34e8aa1994-09-23 14:20:38 +0000850A. Not directly. In many cases you can mimic a?b:c with "a and b or
851c", but there's a flaw: if b is zero (or empty, or None -- anything
852that tests false) then c will be selected instead. In many cases you
853can prove by looking at the code that this can't happen (e.g. because
854b is a constant or has a type that can never be false), but in general
855this can be a problem.
856
857Steve Majewski (or was it Tim Peters?) suggested the following
858solution: (a and [b] or [c])[0]. Because [b] is a singleton list it
859is never false, so the wrong path is never taken; then applying [0] to
860the whole thing gets the b or c that you really wanted. Ugly, but it
861gets you there in the rare cases where it is really inconvenient to
862rewrite your code using 'if'.
863
8644.17. Q. My class defines __del__ but it is not called when I delete the
865object.
866
867A. There are several possible reasons for this.
868
869- The del statement does not necessarily call __del__ -- it simply
870decrements the object's reference count, and if this reaches zero
871__del__ is called.
872
873- If your data structures contain circular links (e.g. a tree where
874each child has a parent pointer and each parent has a list of
875children) the reference counts will never go back to zero. You'll
876have to define an explicit close() method which remvoes those
877pointers. Please don't ever call __del__ directly -- __del__ should
878call close() and close() should make sure that it can be called mor
879than once for the same object.
880
881- If the object has ever been a local variable (or argument, which is
882really the same thing) to a function that caught an expression in an
883except clause, chances are that a reference to the object still exists
884in that function's stack frame as contained in the stack trace.
885Normally, deleting (better: assigning None to) sys.exc_traceback will
886take care of this. If you a stack was printed for an unhandled
887exception in an interactive interpreter, delete sys.last_traceback
888instead.
889
890- There is code that deletes all objects when the interpreter exits,
891but if your Python has been configured to support threads, it is not
892called (because other threads may still be active). You can define
893your own cleanp function using sys.exitfunc (see question 4.4).
894
8954.18. Q. How do I change the shell environment for programs called using
896os.popen() or os.system()? Changing os.environ doesn't work.
897
898A. Modifying the environment passed to subshells was left out of the
899interpreter because there seemed to be no well-established portable
900way to do it.
901
902However if all you want is to pass environment variables to the
903commands run by os.system() or os.popen(), there's a simple solution:
904prefix the command string with a couple of variable assignments and
905export statements. I guess the following would be universal for popen
906(untested):
907
908import os
909from commands import mkarg # nifty routine to add shell quoting
910def epopen(cmd, mode, env = {}):
911 # env is a dictionary of environment variables
912 prefix = ''
913 for key, value in env.values():
914 prefix = prefix + '%s=%s\n' % (key, mkarg(value))
915 prefix = prefix + 'export %s\n' % key
916 return os.popen(prefix + cmd, mode)
917
9184.19. Q. What is a class?
919
920A. A class is the particular object type that is created by executing
921a class statement.
922
9234.20. Q. What is a method?
924
925A. A method is a function that you normally call as
926x.name(arguments...) for some object x. The word is used for methods
927of classes and class instances as well as for methods of built-in
928objects. The latter have a completely different implementation and
929only share the way their calls look in Python code.
930
9314.21. Q. What is self?
932
933A. Self is merely a conventional name for the first argument of a
934method -- i.e. a function defined inside a class definition. A method
935defined as meth(self, a, b, c) should be called as x.meth(a, b, c) for
936some instance x of the class in which the definition occurs;
937the called method will think it is called as meth(x, a, b, c).
938
9394.22. Q. What is a unbound method?
940
941A. An unbound method is a method defined in a class that is not yet
942bound to an instance. You get an unbound method if you ask for a
943class attribute that happens to be a function. You get a bound method
944if you ask for an instance attribute. A bound method knows which
945instance it belongs to and calling it supplies the instance automatic;
946an unbound method only knows which class it wants for its first
947argument (a derived class is also OK). Calling an unbound method
948doesn't "magically" derive the first argument from the context -- you
949have to provide it explicitly.
950
9514.23. Q. How do I call a method defined in a base class from a derived class
952that overrides it?
953
954A. If your class definition starts with "class Derived(Base): ..."
955then you can call method meth defined in Base (or one of Base's base
956classes) as Base.meth(self, arguments...). Here, Base.meth is an
957unbound method (see previous question).
958
9594.24. Q. How do I call a method from a base class without using the name of
960the base class?
961
962A. DON'T DO THIS. REALLY. I MEAN IT. It appears that you could call
963self.__class__.__bases__[0].meth(self, arguments...) but this fails when
964a doubly-derived method is derived from your clas: for its instances,
965self.__class__.__bases__[0] is your class, not its base class -- so
966(assuming you are doing this from within Derived.meth) you would start
967a recursive call.
968
9694.25. Q. How can I organize my code to make it easier to change the base
970class?
971
972A. You could define an alias for the base class, assign the real base
973class to it before your class definition, and use the alias throughout
974your class. Then all you have to change is the value assigned to the
975alias. Incidentally, this trick is also handy if you want to decide
976dynamically (e.g. depending on availability of resources) which base
977class to use. Example:
978
979BaseAlias = <real base class>
980class Derived(BaseAlias):
981 def meth(self):
982 BaseAlias.meth(self)
983 ...
984
9854.26. Q. How can I find the methods or attributes of an object?
986
987A. This depends on the object type.
988
989For an instance x of a user-defined class, instance attributes are
990found in the dictionary x.__dict__, and methods and attributes defined
991by its class are found in x.__class__.__bases__[i].__dict__ (for i in
992range(len(x.__class__.__bases__))). You'll have to walk the tree of
993base classes to find *all* class methods and attributes.
994
995Many, but not all built-in types define a list of their method names
996in x.__methods__, and if they have data attributes, their names may be
997found in x.__members__. However this is only a convention.
998
999For more information, read the source of the standard (but
1000undocumented) module newdir.
1001
10024.27. Q. I can't seem to use os.read() on a pipe created with os.popen().
1003
1004A. os.read() is a low-level function which takes a file descriptor (a
1005small integer). os.popen() creates a high-level file object -- the
1006same type used for sys.std{in,out,err} and returned by the builtin
1007open() function. Thus, to read n bytes from a pipe p created with
1008os.popen(), you need to use p.read(n).
Guido van Rossuma7925f11994-01-26 10:20:16 +00001009
10105. Extending Python
1011===================
1012
10135.1. Q. Can I create my own functions in C?
1014
1015A. Yes, you can create built-in modules containing functions,
Guido van Rossum24349991994-02-02 14:12:45 +00001016variables, exceptions and even new types in C. This is explained in
1017the document "Extending and Embedding the Python Interpreter" (the
1018LaTeX file Doc/ext.tex). Also read the chapter on dynamic loading.
Guido van Rossuma7925f11994-01-26 10:20:16 +00001019
10205.2. Q. Can I create my own functions in C++?
1021
1022A. Yes, using the C-compatibility features found in C++. Basically
1023you place extern "C" { ... } around the Python include files and put
1024extern "C" before each function that is going to be called by the
1025Python interpreter. Global or static C++ objects with constructors
1026are probably not a good idea.
1027
Guido van Rossum7ce61c11994-06-13 15:13:56 +000010285.3. Q. How can I execute arbitrary Python statements from C?
1029
1030A. The highest-level function to do this is run_command() which takes
1031a single string argument which is executed in the context of module
1032__main__ and returns 0 for success and -1 when an exception occurred
1033(including SyntaxError). If you want more control, use run_string();
1034see the source for run_command() in Python/pythonrun.c.
1035
10365.4. Q. How can I evaluate an arbitrary Python expression from C?
1037
1038A. Call the function run_string() from the previous question with the
1039start symbol eval_input; it then parses an expression, evaluates it
1040and returns its value. See exec_eval() in Python/bltinmodule.c.
1041
10425.5. Q. How do I extract C values from a Python object?
1043
1044A. That depends on the object's type. If it's a tuple,
1045gettuplesize(o) returns its length and gettupleitem(o, i) returns its
1046i'th item; similar for lists with getlistsize(o) and getlistitem(o,
1047i). For strings, getstringsize(o) returns its length and
1048getstringvalue(o) a pointer to its value (note that Python strings may
1049contain null bytes so strlen() is not safe). To test which type an
1050object is, first make sure it isn't NULL, and then use
1051is_stringobject(o), is_tupleobject(o), is_listobject(o) etc.
1052
10535.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
1054
1055A. You can't. Use t = newtupleobject(n) instead, and fill it with
1056objects using settupleitem(t, i, o) -- note that this "eats" a
1057reference count of o. Similar for lists with newlistobject(n) and
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00001058setlistitem(l, i, o). Note that you *must* set all the tuple items to
1059some value before you pass the tuple to Python code --
1060newtupleobject(n) initializes them to NULL, which isn't a valid Python
1061value.
1062
10635.7. Q. What happened to mktuple(), featuring in an example in the
1064Extensions manual?
1065
1066A. It's a typo, I meant newtupleobject() (see previous question).
1067
10685.8. Q. How do I call an object's method from C?
1069
1070A. Here's a function (untested) that might become part of the next
1071release in some form. It uses <stdarg.h> to allow passing the
1072argument list on to vmkvalue():
1073
1074object *call_method(object *inst, char *methodname, char *format, ...)
1075{
1076 object *method;
1077 object *args;
1078 object *result;
1079 va_list va;
1080 method = getattr(inst, methodname);
1081 if (method == NULL) return NULL;
1082 va_start(va, format);
1083 args = vmkvalue(format, va);
1084 va_end(va);
1085 if (args == NULL) {
1086 DECREF(method);
1087 return NULL;
1088 }
1089 result = call_object(method, args);
1090 DECREF(method);
1091 DECREF(args);
1092 return result;
1093}
1094
1095This works for any instance that has methods -- whether built-in or
1096user-defined. You are responsible for eventually DECREF'ing the
1097return value.
1098
1099To call, e.g., a file object's "seek" method with arguments 10, 0
1100(assuming the file object pointer is "f"):
1101
1102res = call_method(f, "seek", "(OO)", 10, 0);
1103if (res == NULL) {
1104 ... an exception occurred ...
1105}
1106else {
1107 DECREF(res);
1108}
1109
1110Note that since call_object() *always* wants a tuple for the argument
1111list, to call a function without arguments, pass "()" for the format,
1112and to call a function with one argument, surround the argument in
1113parentheses, e.g. "(i)".
1114
11155.9. Q. How do I catch the output from print_error()?
1116
1117A. (Due to Mark Hammond):
1118
1119* in Python code, define an object that supports the "write()" method.
1120FWIW, there seems to be a small problem that requires the 'softspace'
1121attribute to be defined too (I cant remember exact details of the
1122problem).
1123
1124* redirect sys.stdout and sys.stderr to this object.
1125
1126* call print_error, or just allow the standard traceback mechansim to
1127work.
1128
1129Then, the output will go whereever your write() method sends it.
1130
11315.10. Q. How do I access a module written in Python from C?
1132
1133A. You can get a pointer to the module object as follows:
1134
1135 module = import_module("<modulename>");
1136
1137If the module hasn't been imported yet (i.e. it is not yet present in
1138sys.modules), this initializes the module; otherwise it simply returns
1139the value of sys.modules["<modulename>"]. Note that it doesn't enter
1140the module into any namespace -- it only ensures it has been
1141initialized and is stored in sys.modules.
1142
1143You can then access the module's attributes (i.e. any name defined in
1144the module) as follows:
1145
1146 attr = getattr(module, "<attrname>");
1147
1148Calling setattr(), to assign to variables in the module, also works.
Guido van Rossum7ce61c11994-06-13 15:13:56 +00001149
Guido van Rossuma7925f11994-01-26 10:20:16 +00001150
11516. Python's design
1152==================
1153
11546.1. Q. Why isn't there a generic copying operation for objects in
1155Python?
1156
1157A. Hmm. Maybe there should be one, but it's difficult to assign a
1158useful meaning to copying of open files, sockets and windows, or
1159recursive data structures. As long as you design all your classes
1160yourself you are of course free to define a standard base class that
1161defines an overridable copying operation for all the objects you care
1162about. (One practical point: it would have to be a built-in function,
1163not a standard method name, since not all built-in object types have
1164methods; e.g. strings, integers and tuples don't.)
1165
11666.2. Q. Why isn't there a generic way to implement persistent objects
1167in Python? (Persistent == automatically saved to and restored from
1168disk.)
1169
1170A. Hmm, hmm. Basically for the same reasons as why there is no
1171generic copying operation.
1172
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00001173However, since there is a real desire to have persistent operations,
1174I'm thinking of extending the marshal module to support object sharing
1175(and hence recursive objects) and to extend the list of supported
1176types considerably. For user-defined classes, hooks with __*__ names
1177will allow the class to modify the way their instances are dumped and
1178loaded. Built-in types (including those defined by new extensions)
1179may also define dump/load hooks. There are several problems still to
1180solve, e.g. how do you reliably find the class of which an object is
1181an instance at load time -- assuming the class itself is loaded from
1182some module, and not part of the dumped data. It is also necessary to
1183separate the functionality of converting a set of objects into a byte
1184stream from which they can be reloaded, from the ability to save these
1185byte streams as files and being able to reference an object by a
1186persistent global name.
1187
Guido van Rossuma7925f11994-01-26 10:20:16 +000011886.3. Q. Why isn't there a switch or case statement in Python?
1189
1190A. You can do this easily enough with a sequence of
1191if... elif... elif... else. There have been some proposals for switch
1192statement syntax, but there is no concensus (yet) on whether and how
1193to do range tests.
1194
Guido van Rossumc50158e1994-05-31 09:18:50 +000011956.4. Q. Why does Python use indentation for grouping of statements?
1196
1197A. Basically I believe that using indentation for grouping is
1198extremely elegant and contributes a lot to the clarity of the average
1199Python program. Most people learn to love this feature after a while.
1200Some arguments for it:
1201
1202- Since there are no begin/end brackets there cannot be a disagreement
1203between grouping perceived by the parser and the human reader. I
1204remember long ago seeing a C fragment like this:
1205
1206 if (x <= y)
1207 x++;
1208 y--;
1209 z++;
1210
1211and staring a long time at it wondering why y was being decremented
1212even for x > y... (And I wasn't a C newbie then either.)
1213
1214- Since there are no begin/end brackets there can be no conflicting
1215coding styles. In C there are loads of different ways to place the
1216braces (including the choice whether to place braces around single
1217statements in certain cases, for consistency). If you're used to
1218reading (and writing) code that uses one style, you will feel at least
1219slightly uneasy when reading (or being required to write) another
1220style.
1221
1222- Many coding styles place begin/end brackets on a line by themself.
1223This makes programs considerably longer and wastes valuable screen
1224space, making it harder to get a good overview over a program.
1225Ideally, a function should fit on one basic tty screen (say, 20
1226lines). 20 lines of Python are worth a LOT more than 20 lines of C.
1227This is not solely due to the lack of begin/end brackets (the lack of
1228declarations also helps, and the powerful operations of course), but
1229it certainly helps!
1230
Guido van Rossum3de27361994-07-25 14:19:33 +000012316.5. Q. Why are Python strings immutable?
1232
1233A. There are two advantages. One is performance: knowing that a
1234string is immutable makes it easy to lay it out at construction time
1235-- fixed and unchanging storage requirements. (This is also one of
1236the reasons for the the distinction between tuples and lists.) The
1237other is that strings in Python are considered as "elemental" as
1238numbers. No amount of activity will change the value 8 to anything
1239else, and in Python, no amount of activity will change the string
1240"eight" to anything else. (Adapted from Jim Roskind)
1241
12426.6. Q. Why don't strings have methods like index() or sort(), like
1243lists?
1244
1245A. Good question. Strings currently don't have methods at all
1246(likewise tuples and numbers). Long ago, it seemed unnecessary to
1247implement any of these functions in C, so a standard library module
1248"string" written in Python was created that performs string related
1249operations. Since then, the cry for performance has moved most of
1250them into the built-in module strop (this is imported by module
Guido van Rossumf8c76d01994-08-17 12:19:53 +00001251string, which is still the preferred interface, without loss of
Guido van Rossum3de27361994-07-25 14:19:33 +00001252performance except during initialization). Some of these functions
1253(e.g. index()) could easily be implemented as string methods instead,
1254but others (e.g. sort()) can't, since their interface prescribes that
1255they modify the object, while strings are immutable (see the previous
1256question).
1257
12586.7. Q. Why does Python use methods for some functionality
1259(e.g. list.index()) but functions for other (e.g. len(list))?
1260
1261A. Functions are used for those operations that are generic for a
1262group of types and which should work even for objects that don't have
1263methods at all (e.g. numbers, strings, tuples). Also, implementing
1264len(), max(), min() as a built-in function is actually less code than
1265implementing them as methods for each type. One can quibble about
1266individual cases but it's really too late to change such things
1267fundamentally now.
1268
12696.8. Q. Why can't I derive a class from built-in types (e.g. lists or
1270files)?
1271
1272A. This is caused by the relatively late addition of (user-defined)
1273classes to the language -- the implementation framework doesn't easily
1274allow it. See the answer to question 4.2 for a work-around. This
1275*may* be fixed in the (distant) future.
1276
12776.9. Q. Why must 'self' be declared and used explicitly in method
1278definitions and calls?
1279
1280A. By asking this question you reveal your C++ background. :-)
1281When I added classes, this was (again) the simplest way of
1282implementing methods without too many changes to the interpreter. I
1283borrowed the idea from Modula-3. It turns out to be very useful, for
1284a variety of reasons.
1285
1286First, it makes it more obvious that you are using a method or
1287instance attribute instead of a local variable. Reading "self.x" or
1288"self.meth()" makes it absolutely clear that an instance variable or
1289method is used even if you don't know the class definition by heart.
1290In C++, you can sort of tell by the lack of a local variable
1291declaration (assuming globals are rare or reasily recognizable) -- but
1292in Python, there are no local variable declarations, so you'd have to
1293look up the class definition to be sure.
1294
1295Second, it means that no special syntax is necessary if you want to
1296explicitly reference or call the method from a particular class. In
1297C++, if you want to use a method from base class that is overridden in
1298a derived class, you have to use the :: operator -- in Python you can
1299write baseclass.methodname(self, <argument list>). This is
1300particularly useful for __init__() methods, and in general in cases
1301where a derived class method wants to extend the base class method of
1302the same name and thus has to call the base class method somehow.
1303
1304Lastly, for instance variables, it solves a syntactic problem with
1305assignment: since local variables in Python are (by definition!) those
1306variables to which a value assigned in a function body (and that
1307aren't explicitly declared global), there has to be some way to tell
1308the interpreter that an assignment was meant to assign to an instance
1309variable instead of to a local variable, and it should preferably be
1310syntactic (for efficiency reasons). C++ does this through
1311declarations, but Python doesn't have declarations and it would be a
1312pity having to introduce them just for this purpose. Using the
1313explicit "self.var" solves this nicely. Similarly, for using instance
1314variables, having to write "self.var" means that references to
1315unqualified names inside a method don't have to search the instance's
1316directories.
1317
Guido van Rossumb34e8aa1994-09-23 14:20:38 +000013186.10. Q. Can't you emulate threads in the interpreter instead of
1319relying on an OS-specific thread implementation?
1320
1321A. Unfortunately, the interpreter pushes at least one C stack frame
1322for each Python stack frame. Also, extensions can call back into
1323Python at almost random moments. Therefore a complete threads
1324implementation requires thread support for C.
1325
Guido van Rossuma7925f11994-01-26 10:20:16 +00001326
13277. Using Python on non-UNIX platforms
1328=====================================
1329
Guido van Rossum91f60831994-02-15 15:52:27 +000013307.1. Q. Is there a Mac version of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +00001331
Guido van Rossum91f60831994-02-15 15:52:27 +00001332A. Yes. It is on most ftp sites carrying Python as python.sea.hqx --
1333this is a self-extracting archive containing the application binary as
1334well as the Lib modules.
Guido van Rossuma7925f11994-01-26 10:20:16 +00001335
Guido van Rossum91f60831994-02-15 15:52:27 +000013367.2. Q. Is there a DOS version of Python?
Guido van Rossuma7925f11994-01-26 10:20:16 +00001337
Guido van Rossum91f60831994-02-15 15:52:27 +00001338A. Yes. More than one, actually: 16python.exe runs in standard DOS
1339mode on 186 CPUs or higher; 32python.exe uses a DOS extender and only
1340runs on a 386 or higher CPUs. Although 16python.exe does not pass the
1341test set because test_grammar is too big for the parser, it actually
1342has about 270 kbyte of allocatable heap space, which is sufficient for
1343fairly large programs. 32python.exe is distributed as a tar file
1344containing the required DOS extended and 387 emulator. Both are on
1345most ftp sites carrying Python.
Guido van Rossuma7925f11994-01-26 10:20:16 +00001346
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00001347The file dosbuild.tar.gz on the standard ftp sites
1348(e.g. ftp.cwi.nl:/pub/python/) contains rudimentary Makefiles and
1349instructions.
1350
Guido van Rossum91f60831994-02-15 15:52:27 +000013517.3. Q. Is there a Windows version of Python?
1352
1353A. Yes. Use qwpython.exe. The only problem with it: ^C
1354unconditionally kills the entire program -- it does not raise
1355KeyboardInterrupt. You can also run 16python.exe or 32python.exe in a
1356"DOS box", but qwpython.exe appears to be slightly faster.
1357
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00001358There aren't any Makefiles at this moment. Sorry.
1359
1360Using Win32s (a free NT compatibility package by Microsoft) you can
1361also use the NT version by Mark Hammond -- the Win32s package is also
1362in that directory (you'll need several MB of disk space to install
1363it). See the next question.
1364
Guido van Rossum91f60831994-02-15 15:52:27 +000013657.4. Q. Is there a Windows NT version of Python?
1366
1367A. Yes. Use ntpython.exe. This is for Intel CPUs. If you want a
1368Windows user interface, use qwpython.exe.
1369
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00001370Mark Hammond <MHammond@cmutual.com.au> is building a better NT port.
1371This supports using DLLs for dynamic loading of Python modules, and
1372includes an interface to the Microsoft Foundation Classes and a Python
1373programming environment using it that's written mostly in Python. A
1374prerelease (source and binaries) can be ftp'ed from
1375ftp.cwi.nl:/pub/python/nt/ -- most mirrors will also have this. A
1376thread module is also planned but currently low on Mark's list of
1377priorities.
1378
Guido van Rossum7ce61c11994-06-13 15:13:56 +000013797.5. Q. Is there an OS/2 version of Python?
1380
1381A. Yes. You can ftp it (from ftp.cwi.nl in pub/python, or from the
1382mirror sites) as pyth_os2.zip. This contains both an executable and
1383Makefiles for those fortunate enough to have a C compiler.
1384
Guido van Rossumb34e8aa1994-09-23 14:20:38 +000013857.6. Q. Is there a VMS version of Python?
1386
1387A. I think not (yet). This question has been asked on the list
1388several times and I've never seen an answer. Maybe someone with a VMS
1389C compiler could attempt a port? Probably coming up with proper
1390Makefiles, config.h and config.c should be sufficient. If you succeed
1391(or even if you get stuck halfway), please let me know! (Info as of
139223 September 1994.)
1393
13947.7. Q. What about IBM mainframes, or other esoteric non-UNIX
1395platforms?
1396
1397A. Basically, the same story as for VMS... (Info as of 23 September
13981994.)
1399
1400For ports of Windows NT to non-Intel platforms, the normal NT port
1401should work except you may have to use a different Makefile.
1402(Unconfirmed suggestions from the Python list.)
1403
14047.8. Q. Where are the source or Makefiles for the non-UNIX versions?
1405
1406A. The standard sources can (almost) be used. See the previous
1407questions for availability of Makefiles/projects or patches. If you
1408find things in the standard sources that don't work on your particular
1409platform, please let me know and I'll integrate a solution into the
1410next release of the standard sources. If you submit a fix, please use
1411some kind of #ifdef so as to keep the source working for other
1412platforms. In particular, if the patch works around the availability
1413of a particular function of header file, you should mimic the
1414HAVE_... style used by the configure script -- you can then submit a
1415config.h file for a particular platform so there are no absolutely
1416platform-specific #ifdefs in the rest of the sources.
1417
14187.9. Q. What is the status and support for the non-UNIX versions?
1419
1420A. I don't have access to most of these platforms, so in general I am
1421dependent on material submitted by volunteers(*). However I strive to
1422integrate all changes needed to get it to compile on a particular
1423platform back into the standard sources, so porting of the next
1424version to the various non-UNIX platforms should be easy.
1425
1426(*) For the Macintosh, that volunteer is me.
1427
14287.10. Q. I have the PC version but it appears to be only a binary.
Guido van Rossum7ce61c11994-06-13 15:13:56 +00001429Where's the library?
Guido van Rossuma7925f11994-01-26 10:20:16 +00001430
1431A. You still need to copy the files from the distribution directory
Guido van Rossum91f60831994-02-15 15:52:27 +00001432"python/Lib" to your system. If you don't have the full distribution,
Guido van Rossum3de27361994-07-25 14:19:33 +00001433you can get the file pythonlib<version>.tar.gz from most ftp sites
1434carrying Python; this is a subset of the distribution containing just
1435those file.
Guido van Rossuma7925f11994-01-26 10:20:16 +00001436
Guido van Rossum5333c5d1994-04-11 11:06:22 +00001437Once you have installed the library, you need to point sys.path to it.
1438Assuming the library is in C:\misc\python\lib, the following commands
1439will point your Python interpreter to it (note the doubled backslashes
1440-- you can also use single forward slashes instead):
1441
1442 >>> import sys
1443 >>> sys.path.insert(0, 'C:\\misc\\python\\lib')
1444 >>>
1445
1446For a more permanent effect, set the environment variable PYTHONPATH,
1447as follows (talking to a DOS prompt):
1448
1449 C> SET PYTHONPATH=C:\misc\python\lib
1450
Guido van Rossumb34e8aa1994-09-23 14:20:38 +000014517.11. Q. Where's the documentation for the Mac or PC version?
Guido van Rossuma7925f11994-01-26 10:20:16 +00001452
1453A. There isn't any. The documentation for the Unix version also
Guido van Rossum91f60831994-02-15 15:52:27 +00001454applies to the Mac and PC versions. Where applicable, differences
Guido van Rossuma7925f11994-01-26 10:20:16 +00001455are indicated in the text.
1456
Guido van Rossumb34e8aa1994-09-23 14:20:38 +000014577.12. Q. The Mac (PC) version doesn't seem to have any facilities for
Guido van Rossum91f60831994-02-15 15:52:27 +00001458creating or editing programs apart from entering it interactively, and
1459there seems to be no way to save code that was entered interactively.
1460How do I create a Python program on the Mac (PC)?
Guido van Rossuma7925f11994-01-26 10:20:16 +00001461
Guido van Rossumb34e8aa1994-09-23 14:20:38 +00001462A. Use an external editor. On the Mac, BBEdit seems to be a popular
1463no-frills text editor. I work like this: start the interpreter; edit
1464a module file using BBedit; import and test it in the interpreter;
1465edit again in BBedit; then use the built-in function reload() to
1466re-read the imported module; etc.
Guido van Rossum5333c5d1994-04-11 11:06:22 +00001467
1468Regarding the same question for the PC, Kurt Wm. Hemr writes: "While
1469anyone with a pulse could certainly figure out how to do the same on
1470MS-Windows, I would recommend the NotGNU Emacs clone for MS-Windows.
1471Not only can you easily resave and "reload()" from Python after making
1472changes, but since WinNot auto-copies to the clipboard any text you
1473select, you can simply select the entire procedure (function) which
1474you changed in WinNot, switch to QWPython, and shift-ins to reenter
1475the changed program unit."