annotate Misc/FAQ @ 5215:f70042c19c57 legacy-trunk

Added two new questions about number conversions.
author Guido van Rossum <guido@python.org>
date Tue, 25 Mar 1997 18:25:20 +0000
parents 5878a5af3148
children b0d9de3786ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 Subject: FAQ: Python -- an object-oriented language
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2 Newsgroups: comp.lang.python,comp.answers,news.answers
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
3 Followup-to: comp.lang.python
4221
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
4 From: guido@cnri.reston.va.us (Guido van Rossum)
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
5 Reply-to: guido@cnri.reston.va.us (Guido van Rossum)
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
6 Expires: Sun, 1 Dec 1996 00:00:00 GMT
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
7 Supersedes: <DxJ3t1.CJv@cwi.nl>
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 Approved: news-answers-request@MIT.Edu
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 Archive-name: python-faq/part1
4221
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
11 Submitted-by: Guido van Rossum <guido@cnri.reston.va.us>
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
12 Version: $Revision$
4408
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
13 Last-modified: $Date$
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 This article contains answers to Frequently Asked Questions about
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 Python (an object-oriented interpreted programming language -- see
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 the answer to question 1.1 for a short overview).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
19 Copyright 1993-1996 Guido van Rossum. Unchanged electronic
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 redistribution of this FAQ is allowed. Printed redistribution only
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 with permission of the author. No warranties.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 Author's address:
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
24 Guido van Rossum
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
25 C.N.R.I.
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
26 1895 Preston White Drive
4221
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
27 Reston, VA 20191
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
28 U.S.A.
4221
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
29 Email: <guido@python.org>, <guido@cnri.reston.va.us>
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 The latest version of this FAQ is available by anonymous ftp from
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
32 <URL:ftp://ftp.python.org/pub/python/doc/FAQ>. It will also be posted
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
33 regularly to the newsgroups comp.answers <URL:news:comp.answers> and
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
34 comp.lang.python <URL:news:comp.lang.python>.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
36 Many FAQs, including this one, are available by anonymous ftp
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
37 <URL:ftp://rtfm.mit.edu/pub/usenet/news.answers/>. The name under
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
38 which a FAQ is archived appears in the Archive-name line at the top of
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
39 the article. This FAQ is archived as python-faq/part1
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
40 <URL:ftp://rtfm.mit.edu/pub/usenet/news.answers/python-faq/part1>.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 There's a mail server on that machine which will send you files from
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 the archive by e-mail if you have no ftp access. You send a e-mail
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
44 message to <mail-server@rtfm.mit.edu> containing the single word help
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
45 in the message body to receive instructions.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 This FAQ is divided in the following chapters:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 1. General information and availability
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 2. Python in the real world
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
51 3. Building Python and Other Known Bugs
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 4. Programming in Python
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 5. Extending Python
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 6. Python's design
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 7. Using Python on non-UNIX platforms
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 To find the start of a particular chapter, search for the chapter number
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 followed by a dot and a space at the beginning of a line (e.g. to
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 find chapter 4 in vi, type /^4\. /).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 Here's an overview of the questions per chapter:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 1. General information and availability
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 1.1. Q. What is Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 1.2. Q. Why is it called Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 1.3. Q. How do I obtain a copy of the Python source?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 1.4. Q. How do I get documentation on Python?
1657
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
68 1.5. Q. Are there other ftp sites that mirror the Python distribution?
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
69 1.6. Q. Is there a newsgroup or mailing list devoted to Python?
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
70 1.7. Q. Is there a WWW page devoted to Python?
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
71 1.8. Q. Is the Python documentation available on the WWW?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
72 1.9. Q. Is there a book on Python, or will there be one out soon?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
73 1.10. Q. Are there any published articles about Python that I can quote?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
74 1.11. Q. Are there short introductory papers or talks on Python?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
75 1.12. Q. How does the Python version numbering scheme work?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
76 1.13. Q. How do I get a beta test version of Python?
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
77 1.14. Q. Are there copyright restrictions on the use of Python?
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
78 1.15. Q. Why was Python created in the first place?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 2. Python in the real world
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 2.1. Q. How many people are using Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 2.2. Q. Have any significant projects been done in Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 2.3. Q. Are there any commercial projects going on using Python?
1533
995a8ef4a5c0 Changes for release of 1.0.0
Guido van Rossum <guido@python.org>
parents: 1529
diff changeset
84 2.4. Q. How stable is Python?
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
85 2.5. Q. What new developments are expected for Python in the future?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
86 2.6. Q. Is it reasonable to propose incompatible changes to Python?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
87 2.7. Q. What is the future of Python?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
88 2.8. Q. What is the PSA, anyway?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
89 2.9. Q. How do I join the PSA?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
90 2.10. Q. What are the benefits of joining the PSA?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
92 3. Building Python and Other Known Bugs
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
93 3.1. Q. Is there a test set?
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
94 3.2. Q. When running the test set, I get complaints about floating point
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 operations, but when playing with floating point operations I cannot
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 find anything wrong with them.
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
97 3.3. Q. Link errors after rerunning the configure script.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
98 3.4. Q. The python interpreter complains about options passed to a
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
99 script (after the script name).
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
100 3.5. Q. When building on the SGI, make tries to run python to create
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
101 glmodule.c, but python hasn't been built or installed yet.
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
102 3.6. Q. I use VPATH but some targets are built in the source directory.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
103 3.7. Q. Trouble building or linking with the GNU readline library.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
104 3.8. Q. Trouble with socket I/O on older Linux 1.x versions.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
105 3.9. Q. Trouble with prototypes on Ultrix.
4376
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
106 3.10. Q. Other trouble building Python on platform X.
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
107 3.11. Q. How to configure dynamic loading on Linux.
4408
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
108 3.12. Q: I can't get shared modules to work on Linux 2.0 (Slackware96)?
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
109 3.13. Q: Trouble when making modules shared on Linux.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
110 3.14. Q. How to use threads on Linux.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
111 3.15. Q. Errors when linking with a shared library containing C++ code.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
112 3.16. Q. I built with tkintermodule.c enabled but get "Tkinter not found".
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
113 3.17. Q. I built with Tk 4.0 but Tkinter complains about the Tk version.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
114 3.18. Q. Link errors for Tcl/Tk symbols when linking with Tcl/Tk.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
115 3.19. Q. I configured and built Python for Tcl/Tk but "import Tkinter"
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
116 fails.
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
117 3.20. Q. Tk doesn't work right on DEC Alpha.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
118 3.21. Q. Several common system calls are missing from the posix module.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
119 3.22. Q. ImportError: No module named string, on MS Windows.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
120 3.23. Q. Core dump on SGI when using the gl module.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 4. Programming in Python
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
123 4.1. Q. Is there a source code level debugger with breakpoints, step,
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
124 etc.?
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
125 4.2. Q. Can I create an object class with some methods implemented in
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 C and others in Python (e.g. through inheritance)? (Also phrased as:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 Can I use a built-in type as base class?)
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
128 4.3. Q. Is there a curses/termcap package for Python?
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
129 4.4. Q. Is there an equivalent to C's onexit() in Python?
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
130 4.5. Q. When I define a function nested inside another function, the
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 nested function seemingly can't access the local variables of the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 outer function. What is going on? How do I pass local data to a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 nested function?
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
134 4.6. Q. How do I iterate over a sequence in reverse order?
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
135 4.7. Q. My program is too slow. How do I speed it up?
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
136 4.8. Q. When I have imported a module, then edit it, and import it
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 again (into the same Python process), the changes don't seem to take
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 place. What is going on?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
139 4.9. Q. How do I find the current module name?
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
140 4.10. Q. I have a module in which I want to execute some extra code
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
141 when it is run as a script. How do I find out whether I am running as
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
142 a script?
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
143 4.11. Q. I try to run a program from the Demo directory but it fails
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
144 with ImportError: No module named ...; what gives?
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
145 4.12. Q. I have successfully built Python with STDWIN but it can't
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
146 find some modules (e.g. stdwinevents).
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
147 4.13. Q. What GUI toolkits exist for Python?
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
148 4.14. Q. Are there any interfaces to database packages in Python?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
149 4.15. Q. Is it possible to write obfuscated one-liners in Python?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
150 4.16. Q. Is there an equivalent of C's "?:" ternary operator?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
151 4.17. Q. My class defines __del__ but it is not called when I delete the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
152 object.
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
153 4.18. Q. How do I change the shell environment for programs called
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
154 using os.popen() or os.system()? Changing os.environ doesn't work.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
155 4.19. Q. What is a class?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
156 4.20. Q. What is a method?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
157 4.21. Q. What is self?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
158 4.22. Q. What is a unbound method?
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
159 4.23. Q. How do I call a method defined in a base class from a derived
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
160 class that overrides it?
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
161 4.24. Q. How do I call a method from a base class without using the
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
162 name of the base class?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
163 4.25. Q. How can I organize my code to make it easier to change the base
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
164 class?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
165 4.26. Q. How can I find the methods or attributes of an object?
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
166 4.27. Q. I can't seem to use os.read() on a pipe created with os.popen().
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
167 4.28. Q. How can I create a stand-alone binary from a Python script?
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
168 4.29. Q. What WWW tools are there for Python?
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
169 4.30. Q. How do I run a subprocess with pipes connected to both input
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
170 and output?
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
171 4.31. Q. How do I call a function if I have the arguments in a tuple?
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
172 4.32. Q. How do I enable font-lock-mode for Python in Emacs?
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
173 4.33. Q. Is there an inverse to the format operator (a la C's scanf())?
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
174 4.34. Q. Can I have Tk events handled while waiting for I/O?
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
175 4.35. Q. How do I write a function with output parameters (call by reference)?
3865
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
176 4.36. Q. Please explain the rules for local and global variables in Python.
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
177 4.37. Q. How can I have modules that mutually import each other?
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
178 4.38. Q. How do I copy an object in Python?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
179 4.39. Q. How to implement persistent objects in Python? (Persistent ==
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
180 automatically saved to and restored from disk.)
4438
e88b3215e94a Added question about error from misuse of mangled names.
Guido van Rossum <guido@python.org>
parents: 4408
diff changeset
181 4.40. Q. I try to use __spam and I get an error about _SomeClassName__spam.
4543
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
182 4.41. Q. How do I delete a file? And other file questions.
5200
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
183 4.42. Q. How to modify urllib or httplib to support HTTP/1.1?
5201
5878a5af3148 Added note about adding \n to source for exec and compile.
Guido van Rossum <guido@python.org>
parents: 5200
diff changeset
184 4.43. Q. Unexplicable syntax errors in compile() or exec.
5215
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
185 4.44. Q. How do I convert a string to a number?
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
186 4.45. Q. How do I convert a number to a string?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
187
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 5. Extending Python
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 5.1. Q. Can I create my own functions in C?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 5.2. Q. Can I create my own functions in C++?
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
191 5.3. Q. How can I execute arbitrary Python statements from C?
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
192 5.4. Q. How can I evaluate an arbitrary Python expression from C?
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
193 5.5. Q. How do I extract C values from a Python object?
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
194 5.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
195 5.7. Q. How do I call an object's method from C?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
196 5.8. Q. How do I catch the output from print_error()?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
197 5.9. Q. How do I access a module written in Python from C?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
198 5.10. Q. How do I interface to C++ objects from Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
199
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 6. Python's design
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
201 6.1. Q. Why isn't there a switch or case statement in Python?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
202 6.2. Q. Why does Python use indentation for grouping of statements?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
203 6.3. Q. Why are Python strings immutable?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
204 6.4. Q. Why don't strings have methods like index() or sort(), like
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
205 lists?
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
206 6.5. Q. Why does Python use methods for some functionality
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
207 (e.g. list.index()) but functions for other (e.g. len(list))?
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
208 6.6. Q. Why can't I derive a class from built-in types (e.g. lists or
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
209 files)?
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
210 6.7. Q. Why must 'self' be declared and used explicitly in method
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
211 definitions and calls?
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
212 6.8. Q. Can't you emulate threads in the interpreter instead of
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
213 relying on an OS-specific thread implementation?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
214 6.9. Q. Why can't lambda forms contain statements?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
215 6.10. Q. Why don't lambdas have access to variables defined in the
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
216 containing scope?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
217 6.11. Q. Why can't recursive functions be defined inside other functions?
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
218 6.12. Q. Why is there no more efficient way of iterating over a dictionary
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
219 than first constructing the list of keys()?
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
220 6.13. Q. Can Python be compiled to machine code, C or some other language?
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
221 6.14. Q. Why doesn't Python use proper garbage collection?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 7. Using Python on non-UNIX platforms
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
224 7.1. Q. Is there a Mac version of Python?
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
225 7.2. Q. Are there DOS and Windows versions of Python?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
226 7.3. Q. Is there an OS/2 version of Python?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
227 7.4. Q. Is there a VMS version of Python?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
228 7.5. Q. What about IBM mainframes, or other non-UNIX platforms?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
229 7.6. Q. Where are the source or Makefiles for the non-UNIX versions?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
230 7.7. Q. What is the status and support for the non-UNIX versions?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
231 7.8. Q. I have a PC version but it appears to be only a binary.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
232 Where's the library?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
233 7.9. Q. Where's the documentation for the Mac or PC version?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
234 7.10. Q. The Mac (PC) version doesn't seem to have any facilities for
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
235 creating or editing programs apart from entering it interactively, and
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
236 there seems to be no way to save code that was entered interactively.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
237 How do I create a Python program on the Mac (PC)?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
238
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 To find a particular question, search for the question number followed
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 by a dot, a space, and a Q at the beginning of a line (e.g. to find
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 question 4.2 in vi, type /^4\.2\. Q/).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
242
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
243
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 1. General information and availability
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
245 =======================================
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
246
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 1.1. Q. What is Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 A. Python is an interpreted, interactive, object-oriented programming
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 language. It incorporates modules, exceptions, dynamic typing, very
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 high level dynamic data types, and classes. Python combines
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 remarkable power with very clear syntax. It has interfaces to many
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 system calls and libraries, as well as to various window systems, and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 is extensible in C or C++. It is also usable as an extension language
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 for applications that need a programmable interface. Finally, Python
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
256 is portable: it runs on many brands of UNIX, on the Mac, and on PCs
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
257 under MS-DOS, Windows, Windows NT, and OS/2.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
258
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 To find out more, the best thing to do is to start reading the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 tutorial from the documentation set (see a few questions further
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 down).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 1.2. Q. Why is it called Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
265 A. Apart from being a computer scientist, I'm also a fan of "Monty
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 Python's Flying Circus" (a BBC comedy series from the seventies, in
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
267 the -- unlikely -- case you didn't know). It occurred to me one day
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
268 that I needed a name that was short, unique, and slightly mysterious.
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
269 And I happened to be reading some scripts from the series at the
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
270 time... So then I decided to call my language Python. But Python is
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
271 not a joke. And don't you associate it with dangerous reptiles
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
272 either! (If you need an icon, use an image of the 16-ton weight from
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
273 the TV series or of a can of SPAM :-)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
274
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 1.3. Q. How do I obtain a copy of the Python source?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
276
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
277 A. The latest complete Python source distribution is always available
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
278 by anonymous ftp, e.g.
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
279 <URL:ftp://ftp.python.org/pub/python/src/python1.3.tar.gz>. It is a
2661
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
280 gzipped tar file containing the complete C source, LaTeX
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
281 documentation, Python library modules, example programs, and several
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
282 useful pieces of freely distributable software. This will compile and
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
283 run out of the box on most UNIX platforms. (See section 7 for
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
284 non-UNIX information.)
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
285
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
286 Sometimes beta versions of a newer release are available; check the
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
287 subdirectory "beta" of the above-mentioned URL (i.e.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
288 <URL:ftp://ftp.python.org/pub/python/src/beta/>). (At the time of
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
289 writing, beta3 for Python 1.4 is available there, and should be
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
290 checked before reporting problems with version 1.3.)
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
291
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
292 Occasionally a set of patches is issued which has to be applied using
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
293 the patch program. These patches are placed in the same directory,
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
294 e.g. <URL:ftp://ftp.python.org/pub/python/src/patch1.1.1>. (At the time
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
295 of writing, no patches exist.)
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
296
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
297 An index of said ftp directory can be found in the file INDEX. An
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
298 HTML version of the index can be found in the file index.html,
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
299 <URL:ftp://ftp.python.org/pub/python/index.html>.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 1.4. Q. How do I get documentation on Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
303 A. The LaTeX source for the documentation is part of the source
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
304 distribution. If you don't have LaTeX, the latest Python
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
305 documentation set is always available by anonymous ftp, e.g.
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
306 <URL:ftp://ftp.python.org/pub/python/doc/postscript.tar.gz>. It is a
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
307 gzipped tar file containing PostScript files of the reference manual,
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
308 the library manual, and the tutorial. Note that the library manual is
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
309 the most important one of the set, as much of Python's power stems
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
310 from the standard or built-in types, functions and modules, all of
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
311 which are described here. PostScript for a high-level description of
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
312 Python is in the file nluug-paper.ps (a separate file on the ftp
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
313 site).
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
314
1657
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
315 1.5. Q. Are there other ftp sites that mirror the Python distribution?
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
316
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
317 A. The following anonymous ftp sites keep mirrors of the Python
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
318 distribution:
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
319
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
320 USA:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
321
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
322 <URL:ftp://ftp.python.org/pub/python/>
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
323 <URL:ftp://gatekeeper.dec.com/pub/plan/python/>
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
324 <URL:ftp://ftp.uu.net/languages/python/>
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
325 <URL:ftp://ftp.wustl.edu/graphics/graphics/sgi-stuff/python/>
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
326 <URL:ftp://ftp.sterling.com/programming/languages/python/>
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
327 <URL:ftp://uiarchive.cso.uiuc.edu/pub/lang/python/>
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
328 <URL:ftp://ftp.pht.com/mirrors/python/python/>
5156
417462ab8b00 Added new ftp mirror site ftp://ftp.cdrom.com/pub/python/ (Walnut Creek CDROM).
Guido van Rossum <guido@python.org>
parents: 5127
diff changeset
329 <URL:ftp://ftp.cdrom.com/pub/python/>
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
330
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
331 Europe:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
332
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
333 <URL:ftp://ftp.cwi.nl/pub/python/>
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
334 <URL:ftp://ftp.funet.fi/pub/languages/python/>
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
335 <URL:ftp://ftp.sunet.se/pub/lang/python/>
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
336 <URL:ftp://unix.hensa.ac.uk/mirrors/uunet/languages/python/>
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
337 <URL:ftp://ftp.ibp.fr/pub/python/>
4589
961bf9a200dd New URL for Swiss ftp mirror.
Guido van Rossum <guido@python.org>
parents: 4563
diff changeset
338 <URL:ftp://sunsite.cnlab-switch.ch/mirror/python/>
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
339 <URL:ftp://ftp.informatik.tu-muenchen.de/pub/comp/programming/languages/python/>
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
341 Australia:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
342
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
343 <URL:ftp://ftp.dstc.edu.au/pub/python/>
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
344
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
345 Or try archie on the string "python".
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
346
1657
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
347 1.6. Q. Is there a newsgroup or mailing list devoted to Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
348
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
349 A. There is a newsgroup, comp.lang.python <URL:news:comp.lang.python>,
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
350 and a mailing list. The newsgroup and mailing list are gatewayed into
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
351 each other -- if you can read news it's unnecessary to subscribe to
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
352 the mailing list. Send e-mail to <python-list-request@cwi.nl> to
2661
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
353 (un)subscribe to the mailing list. Hypermail archives of (nearly)
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
354 everything posted to the mailing list (and thus the newsgroup) are
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
355 available on our WWW server,
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
356 <URL:http://www.cwi.nl/~guido/hypermail/index.html>. The raw archives
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
357 are also available by ftp, e.g.
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
358 <URL:ftp://ftp.python.org/pub/python/mail/mailinglist.gz>. The
2661
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
359 uncompressed versions of these files can be read with the standard
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
360 UNIX Mail program ("Mail -f file") or with nn ("nn file"). To read
3018
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
361 them using MH, you could use "inc -file file". (The archival service
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
362 has stopped archiving new articles around the end of April 1995. I
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
363 hope to revive it on the PSA server www.python.org sometime in the
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
364 future.)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
365
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
366 1.7. Q. Is there a WWW page devoted to Python?
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
367
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
368 A. Yes, <URL:http://www.python.org/> is the official Python home page.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
369 At the time of writing, this page is not yet completely operational;
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
370 you may have a look at the old Python home page:
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
371 <URL:http://www.cwi.nl/~guido/Python.html> or at the U.S. copy:
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
372 <URL:http://www.python.org/~guido/Python.html>.
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
373
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
374 1.8. Q. Is the Python documentation available on the WWW?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
375
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
376 A. Yes, see <URL:http://www.python.org/> (Python's home page). It
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
377 contains pointers to hypertext versions of the whole documentation set
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
378 (as hypertext, not just PostScript).
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
380 If you wish to browse this collection of HTML files on your own
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
381 machine, it is available bundled up by anonymous ftp,
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
382 e.g. <URL:ftp://ftp.python.org/pub/python/doc/html.tar.gz>.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
384 An Emacs-INFO set containing the library manual is also available by
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
385 ftp, e.g. <URL:ftp://ftp.python.org/pub/python/doc/lib-info.tar.gz>.
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
386
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
387 1.9. Q. Is there a book on Python, or will there be one out soon?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
388
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
389 A. Mark Lutz is writing a Python book for O'Reilly and Associates, to
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
390 be published early 1996. See the outline (in PostScript):
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
391 <URL:http://www.python.org/workshops/1995-05/outlinep.eps>.
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
392
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
393 1.10. Q. Are there any published articles about Python that I can quote?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
394
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 A. So far the only refereed and published article that describes
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 Python in some detail is:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
397
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 Guido van Rossum and Jelke de Boer, "Interactively Testing Remote
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 Servers Using the Python Programming Language", CWI Quarterly, Volume
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 4, Issue 4 (December 1991), Amsterdam, pp 283-303.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
401
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
402 LaTeX source for this paper is available as part of the Python source
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 distribution.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
404
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
405 See also the next section (supposedly Aaron Watters' paper has been
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
406 refereed).
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
407
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
408 1.11. Q. Are there short introductory papers or talks on Python?
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
409
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
410 A. A recent, very entertaining introduction to Python is the tutorial by
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
411 Aaron Watters in UnixWorld Online:
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
412
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
413 Aaron R. Watters: "The What, Why, Who, and Where of Python",
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
414 <URL:http://www.wcmh.com/uworld/archives/95/tutorial/005.html>
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
415
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
416 An olded paper is:
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
417
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 Guido van Rossum, "An Introduction to Python for UNIX/C
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 Programmers", in the proceedings of the NLUUG najaarsconferentie
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
420 1993 (dutch UNIX users group meeting November 1993).
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
421
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 PostScript for this paper and for the slides used for the accompanying
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
423 presentation is available by ftp as
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
424 <URL:ftp://ftp.python.org/pub/python/doc/nluug-paper.ps> and
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
425 <URL:ftp://ftp.python.org/pub/python/doc/nluug-slides.ps>, respectively.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
426
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
427 Slides for a talk on Python that I gave at the Usenix Symposium on
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
428 Very High Level Languages in Santa Fe, NM, USA in October 1994 are
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
429 available as <URL:ftp://ftp.python.org/pub/python/doc/vhll-slides.ps>.
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
430
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
431 1.12. Q. How does the Python version numbering scheme work?
1533
995a8ef4a5c0 Changes for release of 1.0.0
Guido van Rossum <guido@python.org>
parents: 1529
diff changeset
432
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
433 A. Python versions are numbered A.B.C or A.B. A is the major version
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
434 number -- it is only incremented for major changes in functionality or
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
435 source structure. B is the minor version number, incremented for less
1533
995a8ef4a5c0 Changes for release of 1.0.0
Guido van Rossum <guido@python.org>
parents: 1529
diff changeset
436 earth-shattering changes to a release. C is the patchlevel -- it is
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
437 incremented for each new patch release. Not all releases have patch
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
438 releases. Note that in the past, patches have added significant
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
439 changes; in fact the changeover from 0.9.9 to 1.0.0 was the first time
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
440 that either A or B changed!
1533
995a8ef4a5c0 Changes for release of 1.0.0
Guido van Rossum <guido@python.org>
parents: 1529
diff changeset
441
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
442 Beta versions have an additional suffix of "betaN" for some small
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
443 number N. Note that (for instance) all versions labeled 1.4betaN
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
444 *precede* the actual release of 1.4. 1.4b3 is short for 1.4beta3.
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
445
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
446 1.13. Q. How do I get a beta test version of Python?
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
447
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
448 A. If there are any beta releases, they are published in the normal
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
449 source directory (e.g. <URL:ftp://ftp.python.org/pub/python/src/>).
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
450
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
451 1.14. Q. Are there copyright restrictions on the use of Python?
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
452
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
453 A. Hardly. You can do anything you want with the source, as long as
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
454 you leave the copyrights in, and display those copyrights in any
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
455 documentation about Python that you produce. Also, don't use the
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
456 author's institute's name in publicity without prior written
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
457 permission, and don't hold them responsible for anything (read the
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
458 actual copyright for a precise legal wording).
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
459
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
460 In particular, if you honor the copyright rules, it's OK to use Python
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
461 for commercial use, to sell copies of Python in source or binary form,
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
462 or to sell products that enhance Python or incorporate Python (or part
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
463 of it) in some form. I would still like to know about all commercial
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
464 use of Python!
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
465
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
466 1.15. Q. Why was Python created in the first place?
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
467
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
468 A. Here's a *very* brief summary of what got me started:
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
469
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
470 - I had extensive experience with implementing an interpreted language
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
471 in the ABC group at CWI, and from working with this group I had
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
472 learned a lot about language design. This is the origin of many
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
473 Python features, including the use of indentation for statement
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
474 grouping and the inclusion of very-high-level data types (although the
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
475 details are all different in Python).
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
476
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
477 - I had a number of gripes about the ABC language, but also liked many
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
478 of its features. It was impossible to extend the ABC language (or its
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
479 implementation) to remedy my complaints -- in fact its lack of
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
480 extensibility was one of its biggest problems.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
481
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
482 - I had some experience with using Modula-2+ and talked with the
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
483 designers of Modula-3 (and read the M3 report). M3 is the origin of
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
484 the syntax and semantics used for exceptions, and some other Python
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
485 features.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
486
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
487 - I was working in the Amoeba distributed operating system group at
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
488 CWI. We needed a better way to do system administration than by
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
489 writing either C programs or Bourne shell scripts, since Amoeba had
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
490 its own system call interface which wasn't easily accessible from the
3018
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
491 Bourne shell. My experience with error handling in Amoeba made me
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
492 acutely aware of the importance of exceptions as a programming
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
493 language feature.
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
494
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
495 - It occurred to me that a scripting language with a syntax like ABC
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
496 but with access to the Amoeba system calls would fill the need. I
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
497 realized that it would be foolish to write an Amoeba-specific
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
498 language, so I decided that I needed a language that was generally
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
499 extensible.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
500
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
501 - During the 1989 Christmas holidays, I had a lot of time on my hand,
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
502 so I decided to give it a try. During the next year, while still
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
503 mostly working on it in my own time, Python was used in the Amoeba
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
504 project with increasing success, and the feedback from colleagues made
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
505 me add many early improvements.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
506
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
507 - In February 1991, after just over a year of development, I decided
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
508 to post to USENET. The rest is in the Misc/HISTORY file.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
509
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
510
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
511 2. Python in the real world
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
512 ===========================
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
513
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 2.1. Q. How many people are using Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
515
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
516 A. I don't know, but the maximum number of simultaneous subscriptions
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
517 to the Python mailing list before it was gatewayed into the newsgroup
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
518 was about 180 (several of which were local redistribution lists). I
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
519 believe that many active Python users don't bother to subscribe to the
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
520 list, and now that there's a newsgroup the mailing list subscription
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
521 is even less meaningful. I see new names on the newsgroup all the
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
522 time and my best guess is that there are currently at least several
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
523 thousands of users.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
524
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
525 Another statistic is the number of accesses to the Python WWW server.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
526 Have a look at <URL:http://www.python.org/stats/>.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
527
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
528 2.2. Q. Have any significant projects been done in Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
530 A. Here at CWI (the home of Python), we have written a 20,000 line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
531 authoring environment for transportable hypermedia presentations, a
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
532 5,000 line multimedia teleconferencing tool, as well as many many
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
533 smaller programs.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
534
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
535 The University of Virginia uses Python to control a virtual reality
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
536 engine. Contact: Matt Conway <conway@virginia.edu>.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
537
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
538 The ILU project at Xerox PARC can generate Python glue for ILU
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
539 interfaces. See <URL:ftp://ftp.parc.xerox.com/pub/ilu/ilu.html>.
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
540
2660
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
541 The University of California, Irvine uses a student administration
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
542 system called TELE-Vision written entirely in Python. Contact: Ray
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
543 Price <rlprice@uci.edu>.
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
544
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
545 See also the next question.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
546
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
547 If you have done a significant project in Python that you'd like to be
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
548 included in the list above, send me email!
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
549
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
550 2.3. Q. Are there any commercial projects going on using Python?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
551
5157
829c42893181 Remove the list of Python users, replace it with a pointer to the
Guido van Rossum <guido@python.org>
parents: 5156
diff changeset
552 A. Yes, there's lots of commercial activity using Python. See
829c42893181 Remove the list of Python users, replace it with a pointer to the
Guido van Rossum <guido@python.org>
parents: 5156
diff changeset
553 <URL:http://www.python.org/python/Users.html> for a list.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
554
1533
995a8ef4a5c0 Changes for release of 1.0.0
Guido van Rossum <guido@python.org>
parents: 1529
diff changeset
555 2.4. Q. How stable is Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
556
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
557 A. Very stable. While the current version number would suggest it is
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
558 in the early stages of development, in fact new, stable releases
4590
2124f4b97bdd More stale info.
Guido van Rossum <guido@python.org>
parents: 4589
diff changeset
559 (numbered 0.9.x through 1.4) have been coming out roughly every 3 to
2124f4b97bdd More stale info.
Guido van Rossum <guido@python.org>
parents: 4589
diff changeset
560 6 or 12 months for the past four years.
1533
995a8ef4a5c0 Changes for release of 1.0.0
Guido van Rossum <guido@python.org>
parents: 1529
diff changeset
561
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
562 2.5. Q. What new developments are expected for Python in the future?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
563
4590
2124f4b97bdd More stale info.
Guido van Rossum <guido@python.org>
parents: 4589
diff changeset
564 A. Follow the newsgroup discussions! The workshop proceedings
2124f4b97bdd More stale info.
Guido van Rossum <guido@python.org>
parents: 4589
diff changeset
565 (<URL:http://www.python.org/workshops/>) may also contain interesting
2124f4b97bdd More stale info.
Guido van Rossum <guido@python.org>
parents: 4589
diff changeset
566 looks into the future.
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
567
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
568 2.6. Q. Is it reasonable to propose incompatible changes to Python?
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
569
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
570 A. In general, no. There are already millions of lines of Python code
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
571 around the world, so any changes in the language that invalidates more
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
572 than a very small fraction of existing programs has to be frowned
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
573 upon. Even if you can provide a conversion program, there still is
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
574 the problem of updating all documentation. Providing a gradual
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
575 upgrade path is the only way if a feature has to be changed.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
576
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
577 2.7. Q. What is the future of Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
578
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
579 A. If I knew, I'd be rich :-)
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
580
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
581 Seriously, the formation of the PSA (Pyton Software Activity, see
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
582 <URL:http://www.python.org/psa/>) ensures some kind of support even in
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
583 the (unlikely! event that I'd be hit by a bus (actually, here in the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
584 US, a car accident would be more likely :-), were to join a nunnery,
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
585 or would be head-hunted. A large number of Python users have become
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
586 experts at Python programming as well as maintenance of the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
587 implementation, and would easily fill the vacuum created by my
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
588 disappearance.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
589
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
590 In the mean time, I have no plans to disappear -- rather, I am
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
591 committed to improving Python, and my current benefactor, CNRI (see
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
592 <URL:http://www.cnri.reston.va.us>) is just as committed to continue
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
593 its support of Python and the PSA. In fact, we have great plans for
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
594 Python -- we just can't tell yet!
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
595
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
596 2.8. Q. What is the PSA, anyway?
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
597
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
598 A. The Python Software Activity <URL:http://www.python.org/psa/> was
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
599 created by a number of Python aficionados who want Python to be more
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
600 than the product and responsibility of a single individual. It has
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
601 found a home at CNRI <URL:http://www.cnri.reston.va.us>. Anybody who
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
602 wishes Python well should join the PSA.
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
603
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
604 2.9. Q. How do I join the PSA?
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
605
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
606 A. The full scoop is available on the web, see
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
607 <URL:http://www.python.org/psa/Joining.html>. Summary: send a check
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
608 of at least $50 to CNRI/PSA, 1895 Preston White Drive, Suite 100, in
4221
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
609 Reston, VA 20191. Full-time students pay $25. Companies can join for
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
610 a mere $500.
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
611
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
612 2.10. Q. What are the benefits of joining the PSA?
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
613
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
614 A. Like National Public Radio, if not enough people join, Python will
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
615 wither. Your name will be mentioned on the PSA's web server.
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
616 Workshops organized by the PSA <URL:http://www.python.org/workshops/>
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
617 are only accessible to PSA members (you can join at the door). The
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
618 PSA is working on additional benefits, such as reduced prices for
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
619 books and software, and early access to beta versions of Python.
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
620
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
621
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
622 3. Building Python and Other Known Bugs
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
623 =======================================
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
624
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
625 3.1. Q. Is there a test set?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
626
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
627 A. Yes, simply do "import testall" (or "import autotest" if you aren't
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
628 interested in the output). The standard modules whose name begins
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 with "test" together comprise the test. The test set doesn't test
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
630 *all* features of Python but it goes a long way to confirm that a new
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
631 port is actually working. The Makefile contains an entry "make test"
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
632 which runs the autotest module. NOTE: if "make test" fails, run the
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
633 tests manually ("import testall") to see what goes wrong before
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
634 reporting the error.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
635
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
636 3.2. Q. When running the test set, I get complaints about floating point
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
637 operations, but when playing with floating point operations I cannot
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
638 find anything wrong with them.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
639
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
640 A. The test set makes occasional unwarranted assumptions about the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
641 semantics of C floating point operations. Until someone donates a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
642 better floating point test set, you will have to comment out the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
643 offending floating point tests and execute similar tests manually.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
644
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
645 3.3. Q. Link errors after rerunning the configure script.
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
646
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
647 A. It is generally necessary to run "make clean" after a configuration
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
648 change.
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
649
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
650 3.4. Q. The python interpreter complains about options passed to a
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
651 script (after the script name).
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
652
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
653 A. You are probably linking with GNU getopt, e.g. through -liberty.
1784
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
654 Don't. The reason for the complaint is that GNU getopt, unlike System
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
655 V getopt and other getopt implementations, doesn't consider a
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
656 non-option to be the end of the option list. A quick (and compatible)
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
657 fix for scripts is to add "--" to the interpreter, like this:
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
658
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
659 #! /usr/local/bin/python --
1784
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
660
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
661 You can also use this interactively:
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
662
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
663 python -- script.py [options]
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
664
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
665 Note that a working getopt implementation is provided in the Python
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
666 distribution (in Python/getopt.c) but not automatically used.
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
667
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
668 3.5. Q. When building on the SGI, make tries to run python to create
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
669 glmodule.c, but python hasn't been built or installed yet.
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
670
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
671 A. Comment out the line mentioning glmodule.c in Setup and build a
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
672 python without gl first; install it or make sure it is in your $PATH,
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
673 then edit the Setup file again to turn on the gl module, and make
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
674 again. You don't need to do "make clean"; you do need to run "make
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
675 Makefile" in the Modules subdirectory (or just run "make" at the
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
676 toplevel).
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
677
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
678 3.6. Q. I use VPATH but some targets are built in the source directory.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
679
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
680 A. On some systems (e.g. Sun), if the target already exists in the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
681 source directory, it is created there instead of in the build
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
682 directory. This is usually because you have previously built without
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
683 VPATH. Try running "make clobber" in the source directory.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
684
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
685 3.7. Q. Trouble building or linking with the GNU readline library.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
686
2660
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
687 A. Consider using readline 2.0. Some hints:
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
688
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
689 - You can use the GNU readline library to improve the interactive user
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
690 interface: this gives you line editing and command history when
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
691 calling python interactively. You need to configure and build the GNU
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
692 readline library before running the configure script. Its sources are
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
693 no longer distributed with Python; you can ftp them from any GNU
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
694 mirror site, or from its home site
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
695 <URL:ftp://slc2.ins.cwru.edu/pub/dist/readline-2.0.tar.gz> (or a
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
696 higher version number -- using version 1.x is not recommended). Pass
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
697 the Python configure script the option --with-readline=DIRECTORY where
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
698 DIRECTORY is the absolute pathname of the directory where you've built
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
699 the readline library. Some hints on building and using the readline
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
700 library:
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
701
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
702 - On SGI IRIX 5, you may have to add the following
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
703 to rldefs.h:
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
704
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
705 #ifndef sigmask
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
706 #define sigmask(sig) (1L << ((sig)-1))
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
707 #endif
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
708
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
709 - On most systems, you will have to add #include "rldefs.h" to the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
710 top of several source files, and if you use the VPATH feature, you
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
711 will have to add dependencies of the form foo.o: foo.c to the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
712 Makefile for several values of foo.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
713
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
714 - The readline library requires use of the termcap library. A
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
715 known problem with this is that it contains entry points which
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
716 cause conflicts with the STDWIN and SGI GL libraries. The STDWIN
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
717 conflict can be solved (and will be, in the next release of
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
718 STDWIN) by adding a line saying '#define werase w_erase' to the
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
719 stdwin.h file (in the STDWIN distribution, subdirectory H). The
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
720 GL conflict has been solved in the Python configure script by a
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
721 hack that forces use of the static version of the termcap library.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
722
2660
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
723 - Check the newsgroup gnu.bash.bug <URL:news:gnu.bash.bug> for
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
724 specific problems with the readline library (I don't read this group
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
725 but I've been told that it is the place for readline bugs).
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
726
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
727 3.8. Q. Trouble with socket I/O on older Linux 1.x versions.
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
728
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
729 A. Once you've built Python, use it to run the regen.py script in the
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
730 Lib/linux1 directory. Apparently the files as distributed don't match
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
731 the system headers on some Linux versions.
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
732
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
733 3.9. Q. Trouble with prototypes on Ultrix.
1957
38dcb090f48b add warning about ultrix cc
Guido van Rossum <guido@python.org>
parents: 1942
diff changeset
734
38dcb090f48b add warning about ultrix cc
Guido van Rossum <guido@python.org>
parents: 1942
diff changeset
735 A. Ultrix cc seems broken -- use gcc, or edit config.h to #undef
38dcb090f48b add warning about ultrix cc
Guido van Rossum <guido@python.org>
parents: 1942
diff changeset
736 HAVE_PROTOTYPES.
38dcb090f48b add warning about ultrix cc
Guido van Rossum <guido@python.org>
parents: 1942
diff changeset
737
4376
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
738 3.10. Q. Other trouble building Python on platform X.
1533
995a8ef4a5c0 Changes for release of 1.0.0
Guido van Rossum <guido@python.org>
parents: 1529
diff changeset
739
4221
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
740 A. Please email the details to <guido@cnri.reston.va.us> and I'll look
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
741 into it. Please provide as many details as possible. In particular,
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
742 if you don't tell me what type of computer and what operating system
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
743 (and version) you are using it will be difficult for me to figure out
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
744 what is the matter. If you get a specific error message, please email
66913ca7ec47 New email and zip code for Guido
Guido van Rossum <guido@python.org>
parents: 3865
diff changeset
745 it to me too.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
746
4376
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
747 3.11. Q. How to configure dynamic loading on Linux.
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
748
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
749 A. This is now automatic as long as your Linux version uses the ELF
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
750 object format (all recent Linuxes do).
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
751
4408
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
752 3.12. Q: I can't get shared modules to work on Linux 2.0 (Slackware96)?
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
753
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
754 A: This is a bug in the Slackware96 release. The fix is simple:
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
755
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
756 Make sure that there is a link from /lib/libdl.so to /lib/libdl.so.1
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
757 so that the following links are setup:
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
758
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
759 /lib/libdl.so -> /lib/libdl.so.1
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
760 /lib/libdl.so.1 -> /lib/libdl.so.1.7.14
6c771ea38eee Added item about bug in Slackware96 libdl.
Guido van Rossum <guido@python.org>
parents: 4376
diff changeset
761
5126
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
762 You may have to rerun the configure script, after rm'ing the
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
763 config.cache file, before you attempt to rebuild python after this
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
764 fix.
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
765
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
766 3.13. Q: Trouble when making modules shared on Linux.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
767
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
768 A. This happens when you have built Python for static linking and then
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
769 enable *shared* in the Setup file. Shared library code must be
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
770 compiled with "-fpic". If a .o file for the module already exist that
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
771 was compiled for static linking, you must remove it or do "make clean"
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
772 in the Modules directory.
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
773
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
774 3.14. Q. How to use threads on Linux.
4480
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
775
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
776 A. [Greg Stein] I built myself a libpthreads.so from the libc.5.3.12
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
777 distribution (the binary distribution doesn't have pthreads in
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
778 it). Then, I configured Python with --with-threads and then tweaked
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
779 config.h to include a #define _MIT_POSIX_THREADS (or something like
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
780 that, see /usr/include/pthreads.h). It worked fine at that point.
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
781
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
782 Note that I couldn't get threading to "operate well" with any of the
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
783 other thread packages. Prior libc versions didn't integrate well with
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
784 threads, either, so I couldn't use them (e.g. sleep() blocked all
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
785 threads :-( ).
9e853a5f04ff Added answer by Greg Stein about threads on Linux.
Guido van Rossum <guido@python.org>
parents: 4438
diff changeset
786
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
787 3.15. Q. Errors when linking with a shared library containing C++ code.
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
788
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
789 A. Link the main Python binary with C++. Change the definition of
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
790 LINKCC in Modules/Makefile to be your C++ compiler. You may have to
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
791 edit config.c slightly to make it compilable with C++.
2301
adab66fac30e version 1.20
Guido van Rossum <guido@python.org>
parents: 2208
diff changeset
792
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
793 3.16. Q. I built with tkintermodule.c enabled but get "Tkinter not found".
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
794
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
795 A. Tkinter.py (note: upper case T) lives in a subdirectory of Lib,
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
796 Lib/tkinter. If you are using the default module search path, you
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
797 probably didn't enable the line in the Modules/Setup file defining
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
798 TKPATH; if you use the environment variable PYTHONPATH, you'll have to
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
799 add the proper tkinter subdirectory.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
800
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
801 3.17. Q. I built with Tk 4.0 but Tkinter complains about the Tk version.
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
802
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
803 A. Several things could cause this. You most likely have a Tk 3.6
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
804 installation that wasn't completely eradicated by the Tk 4.0
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
805 installation (which tends to add "4.0" to its installed files). You
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
806 may have the Tk 3.6 support library installed in the place where the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
807 Tk 4.0 support files should be (default /usr/local/lib/tk/); you may
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
808 have compiled Python with the old tk.h header file (yes, this actually
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
809 compiles!); you may actually have linked with Tk 3.6 even though Tk
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
810 4.0 is also around. Similar for Tcl 7.4 vs. Tcl 7.3.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
811
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
812 3.18. Q. Link errors for Tcl/Tk symbols when linking with Tcl/Tk.
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
813
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
814 Quite possibly, there's a version mismatch between the Tcl/Tk header
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
815 files (tcl.h and tk.h) and the tck/tk libraries you are using (the
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
816 "-ltk4.0" and "-ltcl7.4" arguments for _tkinter in the Setup file).
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
817 If you have installed both versions 7.4/4.0 and 7.5/4.1 of Tcl/Tk,
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
818 most likely your header files are for The newer versions, but the
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
819 Setup line for _tkinter in some Python distributions references
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
820 7.4/4.0 by default. Changing this to 7.5/4.1 should take care of
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
821 this.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
822
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
823 3.19. Q. I configured and built Python for Tcl/Tk but "import Tkinter"
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
824 fails.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
825
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
826 A. Most likely, you forgot to enable the line in Setup that says
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
827 "TKPATH=:$(DESTLIB)/tkinter".
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
828
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
829 3.20. Q. Tk doesn't work right on DEC Alpha.
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
830
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
831 A. You probably compiled either Tcl, Tk or Python with gcc. Don't.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
832 For this platform, which has 64-bit integers, gcc is known to generate
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
833 broken code. The standard cc (which comes bundled with the OS!)
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
834 works. If you still prefer gcc, at least try recompiling with cc
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
835 before reporting problems to the newsgroup or the author; if this
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
836 fixes the problem, report the bug to the gcc developers instead. (As
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
837 far as we know, there are no problem with gcc on other platforms --
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
838 the instabilities seem to be restricted to the DEC Alpha.) See also
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
839 question 3.6.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
840
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
841 3.21. Q. Several common system calls are missing from the posix module.
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
842
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
843 A. Most likely, *all* test compilations run by the configure script
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
844 are failing for some reason or another. Have a look in config.log to
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
845 see what could be the reason. A common reason is specifying a
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
846 directory to the --with-readline option that doesn't contain the
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
847 libreadline.a file.
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
848
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
849 3.22. Q. ImportError: No module named string, on MS Windows.
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
850
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
851 A. Most likely, your PYTHONPATH environment variable should be set to
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
852 something like:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
853
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
854 set PYTHONPATH=c:\python;c:\python\lib;c:\python\scripts
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
855
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
856 (assuming Python was installed in c:\python)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
857
4542
652303ef926b Added Q. about enabling *shared* on Linux.
Guido van Rossum <guido@python.org>
parents: 4480
diff changeset
858 3.23. Q. Core dump on SGI when using the gl module.
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
859
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
860 There are conflicts between entry points in the termcap and curses
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
861 libraries and an entry point in the GL library. There's a hack of a
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
862 fix for the termcap library if it's needed for the GNU readline
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
863 library, but it doesn't work when you're using curses. Concluding,
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
864 you can't build a Python binary containing both the curses and gl
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
865 modules.
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
866
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
867
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
868
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
869 4. Programming in Python
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
870 ========================
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
871
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
872 4.1. Q. Is there a source code level debugger with breakpoints, step,
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
873 etc.?
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
874
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
875 A. Yes. Check out module pdb; pdb.help() prints the documentation (or
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
876 you can read it as Lib/pdb.doc). If you use the STDWIN option,
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
877 there's also a windowing interface, wdb. You can write your own
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
878 debugger by using the code for pdb or wdb as an example.
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
879
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
880 4.2. Q. Can I create an object class with some methods implemented in
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
881 C and others in Python (e.g. through inheritance)? (Also phrased as:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
882 Can I use a built-in type as base class?)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
883
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
884 A. No, but you can easily create a Python class which serves as a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
885 wrapper around a built-in object, e.g. (for dictionaries):
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
886
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
887 # A user-defined class behaving almost identical
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
888 # to a built-in dictionary.
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
889 class UserDict:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
890 def __init__(self): self.data = {}
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
891 def __repr__(self): return repr(self.data)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
892 def __cmp__(self, dict):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
893 if type(dict) == type(self.data):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
894 return cmp(self.data, dict)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
895 else:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
896 return cmp(self.data, dict.data)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
897 def __len__(self): return len(self.data)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
898 def __getitem__(self, key): return self.data[key]
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
899 def __setitem__(self, key, item): self.data[key] = item
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
900 def __delitem__(self, key): del self.data[key]
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
901 def keys(self): return self.data.keys()
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
902 def items(self): return self.data.items()
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
903 def values(self): return self.data.values()
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
904 def has_key(self, key): return self.data.has_key(key)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
905
5126
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
906 A2. See Jim Fulton's ExtensionClass for an example of a mechanism
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
907 which allows you to have superclasses which you can inherit from in
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
908 Python -- that way you can have some methods from a C superclass (call
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
909 it a mixin) and some methods from either a Python superclass or your
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
910 subclass. See <URL:http://www.digicool.com/papers/ExtensionClass.html>.
7b940f29621b Two changes:
Guido van Rossum <guido@python.org>
parents: 4590
diff changeset
911
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
912 4.3. Q. Is there a curses/termcap package for Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
913
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
914 A. Yes -- Lance Ellinghaus has written a module that interfaces to
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
915 System V's "ncurses". If you know a little curses and some Python,
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
916 it's straightforward to use. It is part of the standard Python
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
917 distribution, but not configured by default -- you must enable it by
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
918 editing Modules/Setup. It requires a System V curses implementation.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
919
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
920 You could also consider using the "alfa" (== character cell) version
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
921 of STDWIN. (Standard Window System Interface, a portable windowing
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
922 system interface by myself <URL:ftp://ftp.cwi.nl/pub/stdwin/>.) This
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
923 will also prepare your program for porting to windowing environments
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
924 such as X11 or the Macintosh.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
925
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
926 4.4. Q. Is there an equivalent to C's onexit() in Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
927
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
928 A. Yes, if you import sys and assign a function to sys.exitfunc, it
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
929 will be called when your program exits, is killed by an unhandled
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
930 exception, or (on UNIX) receives a SIGHUP or SIGTERM signal.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
931
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
932 4.5. Q. When I define a function nested inside another function, the
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
933 nested function seemingly can't access the local variables of the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
934 outer function. What is going on? How do I pass local data to a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
935 nested function?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
936
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
937 A. Python does not have arbitrarily nested scopes. When you need to
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
938 create a function that needs to access some data which you have
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
939 available locally, create a new class to hold the data and return a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
940 method of an instance of that class, e.g.:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
941
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
942 class MultiplierClass:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
943 def __init__(self, factor):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
944 self.factor = factor
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
945 def multiplier(self, argument):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
946 return argument * self.factor
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
947
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
948 def generate_multiplier(factor):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
949 return MultiplierClass(factor).multiplier
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
950
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
951 twice = generate_multiplier(2)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
952 print twice(10)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
953 # Output: 20
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
954
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
955 An alternative solution uses default arguments, e.g.:
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
956
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
957 def generate_multiplier(factor):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
958 def multiplier(arg, fact = factor):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
959 return arg*fact
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
960 return multiplier
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
961
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
962 twice = generate_multiplier(2)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
963 print twice(10)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
964 # Output: 20
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
965
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
966 4.6. Q. How do I iterate over a sequence in reverse order?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
967
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
968 A. If it is a list, the fastest solution is
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
969
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
970 list.reverse()
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
971 try:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
972 for x in list:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
973 "do something with x"
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
974 finally:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
975 list.reverse()
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
976
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
977 This has the disadvantage that while you are in the loop, the list
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
978 is temporarily reversed. If you don't like this, you can make a copy.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
979 This appears expensive but is actually faster than other solutions:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
980
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
981 rev = list[:]
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
982 rev.reverse()
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
983 for x in rev:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
984 <do something with x>
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
985
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
986 If it isn't a list, a more general but slower solution is:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
987
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
988 i = len(list)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
989 while i > 0:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
990 i = i-1
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
991 x = list[i]
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
992 <do something with x>
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
993
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
994 A more elegant solution, is to define a class which acts as a sequence
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
995 and yields the elements in reverse order (solution due to Steve
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
996 Majewski):
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
997
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
998 class Rev:
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
999 def __init__(self, seq):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1000 self.forw = seq
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1001 def __len__(self):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1002 return len(self.forw)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1003 def __getitem__(self, i):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1004 return self.forw[-(i + 1)]
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1005
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1006 You can now simply write:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1007
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1008 for x in Rev(list):
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1009 <do something with x>
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1010
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1011 Unfortunately, this solution is slowest of all, due to the method
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1012 call overhead...
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1013
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1014 4.7. Q. My program is too slow. How do I speed it up?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1015
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1016 A. That's a tough one, in general. There are many tricks to speed up
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1017 Python code; I would consider rewriting parts in C only as a last
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1018 resort. One thing to notice is that function and (especially) method
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1019 calls are rather expensive; if you have designed a purely OO interface
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1020 with lots of tiny functions that don't do much more than get or set an
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1021 instance variable or call another method, you may consider using a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1022 more direct way, e.g. directly accessing instance variables. Also see
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1023 the standard module "profile" (described in the file
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1024 "python/lib/profile.doc") which makes it possible to find out where
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1025 your program is spending most of its time (if you have some patience
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1026 -- the profiling itself can slow your program down by an order of
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1027 magnitude).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1028
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1029 4.8. Q. When I have imported a module, then edit it, and import it
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1030 again (into the same Python process), the changes don't seem to take
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1031 place. What is going on?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1032
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1033 A. For reasons of efficiency as well as consistency, Python only reads
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1034 the module file on the first time a module is imported. (Otherwise a
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1035 program consisting of many modules, each of which imports the same
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1036 basic module, would read the basic module over and over again.) To
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1037 force rereading of a changed module, do this:
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1038
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1039 import modname
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1040 reload(modname)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1041
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1042 Warning: this technique is not 100% fool-proof. In particular,
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1043 modules containing statements like
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1044
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1045 from modname import some_objects
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1046
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1047 will continue to work with the old version of the imported objects.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1048
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1049 4.9. Q. How do I find the current module name?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1050
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1051 A. A module can find out its own module name by looking at the
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1052 (predefined) global variable __name__. If this has the value
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1053 '__main__' you are running as a script.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1054
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1055 4.10. Q. I have a module in which I want to execute some extra code
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1056 when it is run as a script. How do I find out whether I am running as
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1057 a script?
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1058
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1059 A. See the previous question. E.g. if you put the following on the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1060 last line of your module, main() is called only when your module is
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1061 running as a script:
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1062
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1063 if __name__ == '__main__': main()
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1064
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1065 4.11. Q. I try to run a program from the Demo directory but it fails
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1066 with ImportError: No module named ...; what gives?
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1067
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1068 A. This is probably an optional module (written in C!) which hasn't
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1069 been configured on your system. This especially happens with modules
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1070 like "Tkinter", "stdwin", "gl", "Xt" or "Xm". For Tkinter, STDWIN and
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1071 many other modules, see Modules/Setup.in for info on how to add these
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1072 modules to your Python, if it is possible at all. Sometimes you will
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1073 have to ftp and build another package first (e.g. STDWIN). Sometimes
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1074 the module only works on specific platforms (e.g. gl only works on SGI
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1075 machines).
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1076
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1077 NOTE: if the complaint is about "Tkinter" (upper case T) and you have
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1078 already configured module "tkinter" (lower case t), the solution is
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1079 *not* to rename tkinter to Tkinter or vice versa. There is probably
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1080 something wrong with your module search path. Check out the value of
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1081 sys.path.
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1082
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1083 For X-related modules (Xt and Xm) you will have to do more work: they
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1084 are currently not part of the standard Python distribution. You will
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1085 have to ftp the Extensions tar file, e.g.
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1086 <URL:ftp://ftp.python.org/pub/python/src/extensions.tar.gz> and follow
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1087 the instructions there.
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1088
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1089 See also the next question.
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1090
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1091 4.12. Q. I have successfully built Python with STDWIN but it can't
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1092 find some modules (e.g. stdwinevents).
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1093
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1094 A. There's a subdirectory of the library directory named 'stdwin'
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1095 which should be in the default module search path. There's a line in
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1096 Modules/Setup(.in) that you have to enable for this purpose --
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1097 unfortunately in the latest release it's not near the other
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1098 STDWIN-related lines so it's easy to miss it.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1099
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1100 4.13. Q. What GUI toolkits exist for Python?
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1101
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1102 A. Depending on what platform(s) you are aiming at, there are several.
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1103
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1104 Currently supported solutions:
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1105
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1106 - There's a neat object-oriented interface to the Tcl/Tk widget set,
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1107 called Tkinter. It is part of the standard Python distribution and
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1108 well-supported -- all you need to do is build and install Tcl/Tk and
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1109 enable the _tkinter module and the TKPATH definition in Modules/Setup
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1110 when building Python. This is probably the easiest to install and
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1111 use, and the most complete widget set. It is also very likely that in
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1112 the future the standard Python GUI API will be based on or at least
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1113 look very much like the Tkinter interface. For more info about Tk,
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1114 including pointers to the source, see the Tcl/Tk home page
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1115 <URL:http://www.sunlabs.com/research/tcl/>. Tcl/Tk is now fully
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1116 portable to the Mac and Windows platforms (NT and 95 only); you need
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1117 Python 1.4beta3 or later and Tk 4.1patch1 or later.
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1118
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1119 - There's an interface to X11, including the Athena and Motif widget
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1120 sets (and a few individual widgets, like Mosaic's HTML widget and
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1121 SGI's GL widget) available from
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1122 <URL:ftp://ftp.python.org/pub/python/src/X-extension.tar.gz>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1123 Support by Sjoerd Mullender <sjoerd@cwi.nl>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1124
4376
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
1125 - On top of the X11 interface there's the (recently revived) vpApp
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
1126 toolkit by Per Spilling, now also maintained by Sjoerd Mullender
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
1127 <sjoerd@cwi.nl>. See <URL:ftp://ftp.cwi.nl/pub/sjoerd/vpApp.tar.gz>.
d4f64fc42d84 Toss Q 3.10 on posix.listdir on NeXT. Add revived vpApp.
Guido van Rossum <guido@python.org>
parents: 4278
diff changeset
1128
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1129 - The Mac port has a rich and ever-growing set of modules that support
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1130 the native Mac toolbox calls. See the documentation that comes with
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1131 the Mac port. See <URL:ftp://ftp.python.org/pub/python/mac>. Support
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1132 by Jack Jansen <jack@cwi.nl>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1133
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1134 - The NT port supported by Mark Hammond <MHammond@skippinet.com.au>
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1135 (see question 7.2) includes an interface to the Microsoft Foundation
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1136 Classes and a Python programming environment using it that's written
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1137 mostly in Python. See
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1138 <URL:ftp://ftp.python.org/pub/python/pythonwin/>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1139
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1140 - There's an object-oriented GUI based on the Microsoft Foundation
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1141 Classes model called WPY, supported by Jim Ahlstrom <jim@interet.com>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1142 Programs written in WPY run unchanged and with native look and feel on
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1143 Windows NT/95, Windows 3.1 (using win32s), and on Unix (using Tk).
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1144 Source and binaries for Windows and Linux are available in
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1145 <URL:ftp://ftp.python.org/pub/python/wpy/>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1146
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1147 Obsolete or minority solutions:
3018
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
1148
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
1149 - There's an interface to wxWindows. wxWindows is a portable GUI
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
1150 class library written in C++. It supports XView, Motif, MS-Windows as
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1151 targets. There is some support for Macs and CURSES as well.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1152 wxWindows preserves the look and feel of the underlying graphics
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1153 toolkit. See the wxPython WWW page at
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
1154 <URL:http://www.aiai.ed.ac.uk/~jacs/wx/wxpython/wxpython.html>.
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1155 Support for wxPython (by Harri Pasanen <pa@tekla.fi>) appears
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1156 to have a low priority.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1157
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1158 - For SGI IRIX only, there are unsupported interfaces to the complete
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1159 GL (Graphics Library -- low level but very good 3D capabilities) as
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1160 well as to FORMS (a buttons-and-sliders-etc package built on top of GL
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1161 by Mark Overmars -- ftp'able from
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1162 <URL:ftp://ftp.cs.ruu.nl/pub/SGI/FORMS/>). This is probably also
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1163 becoming obsolete, as OpenGL takes over.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1164
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1165 - There's an interface to STDWIN, a platform-independent low-level
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1166 windowing interface for Mac and X11. This is totally unsupported and
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1167 rapidly becoming obsolete. The STDWIN sources are at
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1168 <URL:ftp://ftp.cwi.nl/pub/stdwin/>. (For info about STDWIN 2.0,
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1169 please refer to Steven Pemberton <steven@cwi.nl> -- I believe it is
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1170 also dead.)
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1171
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1172 - There once was an interface to WAFE, a Tcl interface to the X11
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1173 Motif and Athena widget sets. WAFE is at
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1174 <URL:ftp://ftp.wu-wien.ac.at/pub/src/X11/wafe/>. It's not clear what
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1175 the status of the Python support is.
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
1176
3865
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1177 - (The Fresco port that was mentioned in earlier versions of this FAQ
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1178 no longer seems to exist. Inquire with Mark Linton.)
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2301
diff changeset
1179
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1180 4.14. Q. Are there any interfaces to database packages in Python?
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1181
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1182 A. There's a whole collection of them in the contrib area of the ftp
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1183 server, see <URL:http://www.python.org/ftp/python/contrib/Database/>.
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1184
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1185 4.15. Q. Is it possible to write obfuscated one-liners in Python?
1902
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1186
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1187 A. Yes. See the following three examples, due to Ulf Bartelt:
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1188
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1189 # Primes < 1000
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1190 print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1191 map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000)))
1902
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1192
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1193 # First 10 Fibonacci numbers
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1194 print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1195 range(10))
1902
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1196
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1197 # Mandelbrot set
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1198 print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1199 Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1200 Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1201 i=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
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1202 >=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(
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1203 64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1204 ))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1205 # \___ ___/ \___ ___/ | | |__ lines on screen
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1206 # V V | |______ columns on screen
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1207 # | | |__________ maximum of "iterations"
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1208 # | |_________________ range on y axis
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1209 # |____________________________ range on x axis
1902
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1210
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1211 Don't try this at home, kids!
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1212
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1213 4.16. Q. Is there an equivalent of C's "?:" ternary operator?
1902
53d17c04b42f Added obfuxcated lambda's by Ulf Bertelt
Guido van Rossum <guido@python.org>
parents: 1784
diff changeset
1214
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1215 A. Not directly. In many cases you can mimic a?b:c with "a and b or
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1216 c", but there's a flaw: if b is zero (or empty, or None -- anything
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1217 that tests false) then c will be selected instead. In many cases you
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1218 can prove by looking at the code that this can't happen (e.g. because
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1219 b is a constant or has a type that can never be false), but in general
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1220 this can be a problem.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1221
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1222 Tim Peters (who wishes it was Steve Majewski) suggested the following
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1223 solution: (a and [b] or [c])[0]. Because [b] is a singleton list it
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1224 is never false, so the wrong path is never taken; then applying [0] to
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1225 the whole thing gets the b or c that you really wanted. Ugly, but it
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1226 gets you there in the rare cases where it is really inconvenient to
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1227 rewrite your code using 'if'.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1228
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1229 4.17. Q. My class defines __del__ but it is not called when I delete the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1230 object.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1231
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1232 A. There are several possible reasons for this.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1233
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1234 - The del statement does not necessarily call __del__ -- it simply
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1235 decrements the object's reference count, and if this reaches zero
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1236 __del__ is called.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1237
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1238 - If your data structures contain circular links (e.g. a tree where
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1239 each child has a parent pointer and each parent has a list of
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1240 children) the reference counts will never go back to zero. You'll
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1241 have to define an explicit close() method which removes those
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1242 pointers. Please don't ever call __del__ directly -- __del__ should
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1243 call close() and close() should make sure that it can be called more
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1244 than once for the same object.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1245
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1246 - If the object has ever been a local variable (or argument, which is
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1247 really the same thing) to a function that caught an expression in an
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1248 except clause, chances are that a reference to the object still exists
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1249 in that function's stack frame as contained in the stack trace.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1250 Normally, deleting (better: assigning None to) sys.exc_traceback will
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1251 take care of this. If you a stack was printed for an unhandled
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1252 exception in an interactive interpreter, delete sys.last_traceback
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1253 instead.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1254
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1255 - There is code that deletes all objects when the interpreter exits,
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1256 but if your Python has been configured to support threads, it is not
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1257 called (because other threads may still be active). You can define
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1258 your own cleanup function using sys.exitfunc (see question 4.4).
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1259
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1260 - Finally, if your __del__ method raises an exception, this will be
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1261 ignored. Starting with Python 1.4beta3, a warning message is printed
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1262 to sys.stderr when this happens.
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1263
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1264 4.18. Q. How do I change the shell environment for programs called
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1265 using os.popen() or os.system()? Changing os.environ doesn't work.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1266
5127
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1267 A. You must be using either a version of python before 1.4, or on a
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1268 (rare) system that doesn't have the putenv() library function.
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1269
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1270 Before Python 1.4, modifying the environment passed to subshells was
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1271 left out of the interpreter because there seemed to be no
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1272 well-established portable way to do it (in particular, some systems,
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1273 have putenv(), others have setenv(), and some have none at all). As
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1274 of Python 1.4, almost all Unix systems *do* have putenv(), and so does
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1275 the Win32 API, and thus the os module was modified so that changes to
f22213192531 Change the question about os.environ changes not working -- it now
Guido van Rossum <guido@python.org>
parents: 5126
diff changeset
1276 os.environ are trapped and the corresponding putenv() call is made.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1277
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1278 4.19. Q. What is a class?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1279
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1280 A. A class is the particular object type that is created by executing
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1281 a class statement. Class objects are used as templates, to create
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1282 class instance objects, which embody both the data structure and
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1283 program routines specific to a datatype.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1284
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1285 4.20. Q. What is a method?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1286
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1287 A. A method is a function that you normally call as
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1288 x.name(arguments...) for some object x. The term is used for methods
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1289 of classes and class instances as well as for methods of built-in
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1290 objects. (The latter have a completely different implementation and
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1291 only share the way their calls look in Python code.) Methods of
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1292 classes (and class instances) are defined as functions inside the
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1293 class definition.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1294
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1295 4.21. Q. What is self?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1296
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1297 A. Self is merely a conventional name for the first argument of a
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1298 method -- i.e. a function defined inside a class definition. A method
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1299 defined as meth(self, a, b, c) should be called as x.meth(a, b, c) for
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1300 some instance x of the class in which the definition occurs;
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1301 the called method will think it is called as meth(x, a, b, c).
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1302
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1303 4.22. Q. What is a unbound method?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1304
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1305 A. An unbound method is a method defined in a class that is not yet
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1306 bound to an instance. You get an unbound method if you ask for a
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1307 class attribute that happens to be a function. You get a bound method
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1308 if you ask for an instance attribute. A bound method knows which
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1309 instance it belongs to and calling it supplies the instance automatically;
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1310 an unbound method only knows which class it wants for its first
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1311 argument (a derived class is also OK). Calling an unbound method
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1312 doesn't "magically" derive the first argument from the context -- you
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1313 have to provide it explicitly.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1314
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1315 4.23. Q. How do I call a method defined in a base class from a derived
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1316 class that overrides it?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1317
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1318 A. If your class definition starts with "class Derived(Base): ..."
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1319 then you can call method meth defined in Base (or one of Base's base
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1320 classes) as Base.meth(self, arguments...). Here, Base.meth is an
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1321 unbound method (see previous question).
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1322
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1323 4.24. Q. How do I call a method from a base class without using the
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1324 name of the base class?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1325
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1326 A. DON'T DO THIS. REALLY. I MEAN IT. It appears that you could call
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1327 self.__class__.__bases__[0].meth(self, arguments...) but this fails when
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1328 a doubly-derived method is derived from your class: for its instances,
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1329 self.__class__.__bases__[0] is your class, not its base class -- so
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1330 (assuming you are doing this from within Derived.meth) you would start
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1331 a recursive call.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1332
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1333 4.25. Q. How can I organize my code to make it easier to change the base
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1334 class?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1335
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1336 A. You could define an alias for the base class, assign the real base
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1337 class to it before your class definition, and use the alias throughout
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1338 your class. Then all you have to change is the value assigned to the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1339 alias. Incidentally, this trick is also handy if you want to decide
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1340 dynamically (e.g. depending on availability of resources) which base
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1341 class to use. Example:
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1342
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1343 BaseAlias = <real base class>
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1344 class Derived(BaseAlias):
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1345 def meth(self):
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1346 BaseAlias.meth(self)
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1347 ...
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1348
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1349 4.26. Q. How can I find the methods or attributes of an object?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1350
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1351 A. This depends on the object type.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1352
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1353 For an instance x of a user-defined class, instance attributes are
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1354 found in the dictionary x.__dict__, and methods and attributes defined
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1355 by its class are found in x.__class__.__bases__[i].__dict__ (for i in
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1356 range(len(x.__class__.__bases__))). You'll have to walk the tree of
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1357 base classes to find *all* class methods and attributes.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1358
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1359 Many, but not all built-in types define a list of their method names
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1360 in x.__methods__, and if they have data attributes, their names may be
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1361 found in x.__members__. However this is only a convention.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1362
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1363 For more information, read the source of the standard (but
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1364 undocumented) module newdir.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1365
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1366 4.27. Q. I can't seem to use os.read() on a pipe created with os.popen().
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1367
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1368 A. os.read() is a low-level function which takes a file descriptor (a
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1369 small integer). os.popen() creates a high-level file object -- the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1370 same type used for sys.std{in,out,err} and returned by the builtin
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1371 open() function. Thus, to read n bytes from a pipe p created with
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1372 os.popen(), you need to use p.read(n).
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1373
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1374 4.28. Q. How can I create a stand-alone binary from a Python script?
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1375
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1376 The demo script "Demo/scripts/freeze.py" does what you want. (It's
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1377 actually not a demo but a support tool -- there is some extra code in
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1378 the interpreter to accommodate it.) It requires that you have the
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1379 Python build tree handy, complete with all the lib*.a files.
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1380
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1381 This works by scanning your source recursively for import statements
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1382 (both forms) and looking for the modules on the standard Python path
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1383 as well as in the source directory (for built-in modules). It then
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1384 "compiles" the modules written in Python to C code (array initializers
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1385 that can be turned into code objects using the marshal module) and
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1386 creates a custom-made config file that only contains those built-in
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1387 modules which are actually used in the program. It then compiles the
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1388 generated C code and links it with the rest of the Python interpreter
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1389 to form a self-contained binary which acts exactly like your script.
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1390
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1391 Hint: the freeze program only works if your script's filename ends in
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1392 ".py".
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1393
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1394 4.29. Q. What WWW tools are there for Python?
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1395
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1396 A. See the chapter titled "Internet and WWW" in the Library Reference
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1397 Manual. There's also a web browser written in Python, called Grail --
4563
ea458933fc2a monty -> grail in Grail URL.
Guido van Rossum <guido@python.org>
parents: 4543
diff changeset
1398 see <URL:http://grail.cnri.reston.va.us/grail/>.
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1399
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1400 Steve Miale <smiale@cs.indiana.edu> has written a modular WWW browser
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1401 called Dancer. An alpha version can be FTP'ed from
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1402 <URL:ftp://ftp.cs.indiana.edu/pub/smiale/dancer.tar.gz>. (There are a
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1403 few articles about Dancer in the (hyper)mail archive
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1404 <URL:http://www.cwi.nl/~guido/hypermail/python-1994q3/index.html>.)
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1405
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1406 4.30. Q. How do I run a subprocess with pipes connected to both input
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1407 and output?
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1408
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1409 A. This is really a UNIX question. Also, in general, it is unwise to
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1410 do so, because you can easily cause a deadlock where the parent
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1411 process is blocked waiting for output from the child, while the child
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1412 is blocked waiting for input from the child. This can be caused
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1413 because the parent expects the child to output more text than it does,
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1414 or it can be caused by data being stuck in stdio buffers due to lack
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1415 of flushing. The Python parent can of course explicitly flush the data
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1416 it sends to the child before it reads any output, but if the child is
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1417 a naive C program it can easily have been written to never explicitly
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1418 flush its output, even if it is interactive, since flushing is
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1419 normally automatic.
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1420
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1421 In many cases, all you really need is to run some data through a
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1422 command and get the result back. Unless the data is infinite in size,
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1423 the easiest (and often the most efficient!) way to do this is to write
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1424 it to a temporary file and run the command with that temporary file as
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1425 input. The standard module tempfile exports a function mktemp() which
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1426 generates unique temporary file names.
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1427
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1428 If after reading all of the above you still want to connect two pipes
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1429 to a subprocess's standard input and output, here's a simple solution,
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1430 due to Jack Jansen:
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1431
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1432 import os
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1433 import sys
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1434 import string
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1435
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1436 MAXFD = 100 # Max number of file descriptors in this system
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1437
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1438 def popen2(cmd):
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1439 cmd = string.split(cmd)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1440 p2cread, p2cwrite = os.pipe()
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1441 c2pread, c2pwrite = os.pipe()
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1442 pid = os.fork()
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1443 if pid == 0:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1444 # Child
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1445 os.close(0)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1446 os.close(1)
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1447 if os.dup(p2cread) != 0:
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1448 sys.stderr.write('popen2: bad read dup\n')
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1449 if os.dup(c2pwrite) != 1:
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1450 sys.stderr.write('popen2: bad write dup\n')
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1451 for i in range(3, MAXFD):
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1452 try:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1453 os.close(i)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1454 except:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1455 pass
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1456 try:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1457 os.execv(cmd[0], cmd)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1458 finally:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1459 os._exit(1)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1460 os.close(p2cread)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1461 tochild = os.fdopen(p2cwrite, 'w')
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1462 os.close(c2pwrite)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1463 fromchild = os.fdopen(c2pread, 'r')
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1464 return fromchild, tochild
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1465
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1466 Note that many interactive programs (e.g. vi) don't work well with
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1467 pipes substituted for standard input and output. You will have to use
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1468 pseudo ttys ("ptys") instead of pipes. There is some undocumented
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1469 code to use these in the library module pty.py -- I'm afraid you're on
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
1470 your own here.
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
1471
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
1472 A different answer is a Python interface to Don Libes' "expect"
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
1473 library. A prerelease of this is available on the Python ftp mirror
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
1474 sites in the contrib subdirectory as expy-0.3.tar.gz, e.g.
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
1475 <URL:ftp://ftp.python.org/pub/python/contrib/expy-0.3.tar.gz>.
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
1476
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1477 4.31. Q. How do I call a function if I have the arguments in a tuple?
2660
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1478
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1479 A. Use the built-in function apply(). For instance,
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1480
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1481 func(1, 2, 3)
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1482
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1483 is equivalent to
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1484
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1485 args = (1, 2, 3)
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1486 apply(func, args)
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1487
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1488 Note that func(args) is not the same -- it calls func() with exactly
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1489 one argument, the tuple args, instead of three arguments, the integers
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1490 1, 2 and 3.
4eb6ddb9e961 Some more changes for 1.2
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1491
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1492 4.32. Q. How do I enable font-lock-mode for Python in Emacs?
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1493
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1494 A. Assuming you're already using python-mode and font-lock-mode
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1495 separately, all you need to do is put this in your .emacs file:
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1496
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1497 (defun my-python-mode-hook ()
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1498 (setq font-lock-keywords python-font-lock-keywords)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1499 (font-lock-mode 1))
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
1500 (add-hook 'python-mode-hook 'my-python-mode-hook)
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1501
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1502 4.33. Q. Is there an inverse to the format operator (a la C's scanf())?
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1503
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1504 A. Not as such.
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1505
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1506 For simple input parsing, the easiest approach is usually to split
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1507 the line into whitespace-delimited words using string.split(), and to
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1508 convert decimal strings to numeric values using string.atoi(),
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1509 string.atol() or string.atof(). (Python's atoi() is 32-bit and its
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1510 atol() is arbitrary precision.) If you want to use another delimiter
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1511 than whitespace, use string.splitfield() (possibly combining it with
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1512 string.strip() which removes surrounding whitespace from a string).
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1513
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1514 For more complicated input parsing, regular expressions (see module
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1515 regex) are better suited and more powerful than C's scanf().
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1516
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1517 4.34. Q. Can I have Tk events handled while waiting for I/O?
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1518
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1519 A. Yes, and you don't even need threads! But you'll have to
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1520 restructure your I/O code a bit. Tk has the equivalent of Xt's
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1521 XtAddInput() call, which allows you to register a callback function
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1522 which will be called from the Tk mainloop when I/O is possible on a
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1523 file descriptor. Here's what you need:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1524
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1525 from Tkinter import tkinter
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1526 tkinter.createfilehandler(file, mask, callback)
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1527
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1528 The file may be a Python file or socket object (actually, anything
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1529 with a fileno() method), or an integer file descriptor. The mask is
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1530 one of the constants tkinter.READABLE or tkinter.WRITABLE. The
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1531 callback is called as follows:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1532
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1533 callback(file, mask)
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1534
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1535 You must unregister the callback when you're done, using
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1536
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1537 tkinter.deletefilehandler(file)
3727
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1538
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1539 Note: since you don't know *how many bytes* are available for reading,
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1540 you can't use the Python file object's read or readline methods, since
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1541 these will insist on reading a predefined number of bytes. For
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1542 sockets, the recv() or recvfrom() methods will work fine; for other
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1543 files, use os.read(file.fileno(), maxbytecount).
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1544
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1545 4.35. Q. How do I write a function with output parameters (call by reference)?
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1546
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1547 A. [Mark Lutz] The thing to remember is that arguments are passed by
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1548 assignment in Python. Since assignment just creates references to
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1549 objects, there's no alias between an argument name in the caller and
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1550 callee, and so no call-by-reference per se. But you can simulate it
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1551 in a number of ways:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1552
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1553 1) By using global variables; but you probably shouldn't :-)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1554
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1555 2) By passing a mutable (changeable in-place) object:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1556
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1557 def func1(a):
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1558 a[0] = 'new-value' # 'a' references a mutable list
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1559 a[1] = a[1] + 1 # changes a shared object
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1560
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1561 args = ['old-value', 99]
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1562 func1(args)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1563 print args[0], args[1] # output: new-value 100
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1564
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1565 3) By return a tuple, holding the final values of arguments:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1566
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1567 def func2(a, b):
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1568 a = 'new-value' # a and b are local names
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1569 b = b + 1 # assigned to new objects
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1570 return a, b # return new values
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1571
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1572 x, y = 'old-value', 99
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1573 x, y = func2(x, y)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1574 print x, y # output: new-value 100
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1575
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1576 4) And other ideas that fall-out from Python's object model. For
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1577 instance, it might be clearer to pass in a mutable dictionary:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1578
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1579 def func3(args):
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1580 args['a'] = 'new-value' # args is a mutable dictionary
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1581 args['b'] = args['b'] + 1 # change it in-place
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1582
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1583 args = {'a':' old-value', 'b': 99}
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1584 func3(args)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1585 print args['a'], args['b']
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1586
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1587 5) Or bundle-up values in a class instance:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1588
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1589 class callByRef:
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1590 def __init__(self, **args):
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1591 for (key, value) in args.items():
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1592 setattr(self, key, value)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1593
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1594 def func4(args):
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1595 args.a = 'new-value' # args is a mutable callByRef
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1596 args.b = args.b + 1 # change object in-place
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1597
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1598 args = callByRef(a='old-value', b=99)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1599 func4(args)
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1600 print args.a, args.b
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1601
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1602 But there's probably no good reason to get this complicated :-).
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1603
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1604 [Python' author favors solution 3 in most cases.]
a10a0f6014c4 Some updates. Still out of date.
Guido van Rossum <guido@python.org>
parents: 3233
diff changeset
1605
3865
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1606 4.36. Q. Please explain the rules for local and global variables in Python.
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1607
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1608 A. [Ken Manheimer] In Python, procedure variables are implicitly
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1609 global, unless they assigned anywhere within the block. In that case
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1610 they are implicitly local, and you need to explicitly declare them as
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1611 'global'.
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1612
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1613 Though a bit surprising at first, a moments consideration explains
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1614 this. On one hand, requirement of 'global' for assigned vars provides
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1615 a bar against unintended side-effects. On the other hand, if global
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1616 were required for all global references, you'd be using global all the
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1617 time. Eg, you'd have to declare as global every reference to a
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1618 builtin function, or to a component of an imported module. This
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1619 clutter would defeat the usefulness of the 'global' declaration for
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1620 identifying side-effects.
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1621
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1622 4.37. Q. How can I have modules that mutually import each other?
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1623
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1624 A. Jim Roskind recommends the following order in each module:
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1625
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1626 First: all exports (like globals, functions, and classes that don't
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1627 need imported bases classes).
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1628
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1629 Then: all import statements.
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1630
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1631 Finally: all active code (including globals that are initialized from
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1632 imported values).
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1633
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1634 Python's author doesn't like this approach much because the imports
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1635 appear in a strange place, but has to admit that it works. His
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1636 recommended strategy is to avoid all uses of "from <module> import *"
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1637 (so everything from an imported module is referenced as
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1638 <module>.<name>) and to place all code inside functions.
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1639 Initializations of global variables and class variables should use
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1640 constants or built-in functions only.
4591035228a7 Added two new questions; about globals/locals and about recursive imports.
Guido van Rossum <guido@python.org>
parents: 3727
diff changeset
1641
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1642 4.38. Q. How do I copy an object in Python?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1643
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1644 A. There is no generic copying operation built into Python, however
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1645 most object types have some way to create a clone. Here's how for the
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1646 most common objects:
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1647
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1648 - For immutable objects (numbers, strings, tuples), cloning is
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1649 unnecessary since their value can't change.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1650
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1651 - For lists (and generally for mutable sequence types), a clone is
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1652 created by the expression l[:].
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1653
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1654 - For dictionaries, the following function returns a clone:
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1655
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1656 def dictclone(o):
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1657 n = {}
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1658 for k in o.keys(): n[k] = o[k]
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
1659 return n
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1660
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1661 - Finally, for generic objects, the "copy" module defines two
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1662 functions for copying objects. copy.copy(x) returns a copy as shown
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1663 by the above rules. copy.deepcopy(x) also copies the elements of
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1664 composite objects. See the section on this module in the Library
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1665 Reference Manual.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1666
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1667 4.39. Q. How to implement persistent objects in Python? (Persistent ==
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1668 automatically saved to and restored from disk.)
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1669
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1670 A. The library module "pickle" now solves this in a very general way
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1671 (though you still can't store things like open files, sockests or
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1672 windows), and the library module "shelve" uses pickle and (g)dbm to
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1673 create presistent mappings containing arbitrary Python objects.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1674
4438
e88b3215e94a Added question about error from misuse of mangled names.
Guido van Rossum <guido@python.org>
parents: 4408
diff changeset
1675 4.40. Q. I try to use __spam and I get an error about _SomeClassName__spam.
e88b3215e94a Added question about error from misuse of mangled names.
Guido van Rossum <guido@python.org>
parents: 4408
diff changeset
1676
e88b3215e94a Added question about error from misuse of mangled names.
Guido van Rossum <guido@python.org>
parents: 4408
diff changeset
1677 A. Variables with double leading underscore are "mangled" to provide a
e88b3215e94a Added question about error from misuse of mangled names.
Guido van Rossum <guido@python.org>
parents: 4408
diff changeset
1678 simple but effective way to define class private variables. See the
e88b3215e94a Added question about error from misuse of mangled names.
Guido van Rossum <guido@python.org>
parents: 4408
diff changeset
1679 chapter "New in Release 1.4" in the Python Tutorial.
e88b3215e94a Added question about error from misuse of mangled names.
Guido van Rossum <guido@python.org>
parents: 4408
diff changeset
1680
4543
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1681 4.41. Q. How do I delete a file? And other file questions.
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1682
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1683 A. Use os.remove(filename) or os.unlink(filename); for documentation,
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1684 see the posix section of the library manual. They are the same,
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1685 unlink() is simply the Unix name for this function. In earlier
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1686 versions of Python, only os.unlink() was available.
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1687
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1688 To remove a directory, use os.rmdir(); use os.mkdir() to create one.
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1689
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1690 To rename a file, use os.rename().
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1691
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1692 To truncate a file, open it using f = open(filename, "w+"), and use
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1693 f.truncate(offset); offset defaults to the current seek position.
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1694 There's also os.ftruncate(fd, offset) for files opened with os.open()
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1695 -- for advanced Unix hacks only.
e52054440efc Added os.remove()/unlink(), rmdir(), rename(), and [f]truncate().
Guido van Rossum <guido@python.org>
parents: 4542
diff changeset
1696
5200
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1697 4.42. Q. How to modify urllib or httplib to support HTTP/1.1?
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1698
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1699 A. Apply the following patch to httplib.py:
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1700
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1701 41c41
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1702 < replypat = regsub.gsub('\\.', '\\\\.', HTTP_VERSION) + \
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1703 ---
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1704 > replypat = regsub.gsub('\\.', '\\\\.', 'HTTP/1.[0-9]+') + \
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1705
5201
5878a5af3148 Added note about adding \n to source for exec and compile.
Guido van Rossum <guido@python.org>
parents: 5200
diff changeset
1706 4.43. Q. Unexplicable syntax errors in compile() or exec.
5878a5af3148 Added note about adding \n to source for exec and compile.
Guido van Rossum <guido@python.org>
parents: 5200
diff changeset
1707
5878a5af3148 Added note about adding \n to source for exec and compile.
Guido van Rossum <guido@python.org>
parents: 5200
diff changeset
1708 A. When a statement suite (as opposed to an expression) is compiled by
5878a5af3148 Added note about adding \n to source for exec and compile.
Guido van Rossum <guido@python.org>
parents: 5200
diff changeset
1709 compile(), exec or execfile(), it *must* end in a newline. In some
5878a5af3148 Added note about adding \n to source for exec and compile.
Guido van Rossum <guido@python.org>
parents: 5200
diff changeset
1710 cases, when the source ends in an indented block it appears that at
5878a5af3148 Added note about adding \n to source for exec and compile.
Guido van Rossum <guido@python.org>
parents: 5200
diff changeset
1711 least two newlines are required.
5200
024e738674a5 Added Q. about HTTP/1.1.
Guido van Rossum <guido@python.org>
parents: 5157
diff changeset
1712
5215
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1713 4.44. Q. How do I convert a string to a number?
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1714
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1715 A. To convert, e.g., the string '144' to the number 144, import the
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1716 module string and use the string.atoi() function. For floating point
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1717 numbers, use string.atof(); for long integers, use string.atol(). See
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1718 the library reference manual section for the string module for more
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1719 details. While you could use the built-in function eval() instead of
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1720 any of those, this is not recommended, because someone could pass you
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1721 a Python expression that might have unwanted side effects (like
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1722 reformatting your disk).
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1723
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1724 4.45. Q. How do I convert a number to a string?
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1725
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1726 A. To convert, e.g., the number 144 to the string '144', use the
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1727 built-in function repr() or the backquote notation (these are
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1728 equivalent). If you want a hexadecimal or octal representation, use
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1729 the built-in functions hex() or oct(), respectively. For fancy
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1730 formatting, use the % operator on strings, just like C printf formats,
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1731 e.g. "%04d" % 144 yields '0144' and "%.3f" % (1/3.0) yields '0.333'.
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1732 See the library reference manual for details.
f70042c19c57 Added two new questions about number conversions.
Guido van Rossum <guido@python.org>
parents: 5201
diff changeset
1733
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1734
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1735 5. Extending Python
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1736 ===================
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1737
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1738 5.1. Q. Can I create my own functions in C?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1739
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1740 A. Yes, you can create built-in modules containing functions,
1541
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1741 variables, exceptions and even new types in C. This is explained in
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1742 the document "Extending and Embedding the Python Interpreter" (the
630e03109c63 Released version 1.4; out after 1.0.0 is released...
Guido van Rossum <guido@python.org>
parents: 1535
diff changeset
1743 LaTeX file Doc/ext.tex). Also read the chapter on dynamic loading.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1744
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1745 5.2. Q. Can I create my own functions in C++?
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1746
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1747 A. Yes, using the C-compatibility features found in C++. Basically
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1748 you place extern "C" { ... } around the Python include files and put
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1749 extern "C" before each function that is going to be called by the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1750 Python interpreter. Global or static C++ objects with constructors
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1751 are probably not a good idea.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1752
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1753 5.3. Q. How can I execute arbitrary Python statements from C?
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1754
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1755 A. The highest-level function to do this is run_command() which takes
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1756 a single string argument which is executed in the context of module
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1757 __main__ and returns 0 for success and -1 when an exception occurred
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1758 (including SyntaxError). If you want more control, use run_string();
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1759 see the source for run_command() in Python/pythonrun.c.
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1760
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1761 5.4. Q. How can I evaluate an arbitrary Python expression from C?
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1762
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1763 A. Call the function run_string() from the previous question with the
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1764 start symbol eval_input; it then parses an expression, evaluates it
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1765 and returns its value. See exec_eval() in Python/bltinmodule.c.
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1766
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1767 5.5. Q. How do I extract C values from a Python object?
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1768
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1769 A. That depends on the object's type. If it's a tuple,
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1770 gettuplesize(o) returns its length and gettupleitem(o, i) returns its
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1771 i'th item; similar for lists with getlistsize(o) and getlistitem(o,
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1772 i). For strings, getstringsize(o) returns its length and
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1773 getstringvalue(o) a pointer to its value (note that Python strings may
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1774 contain null bytes so strlen() is not safe). To test which type an
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1775 object is, first make sure it isn't NULL, and then use
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1776 is_stringobject(o), is_tupleobject(o), is_listobject(o) etc.
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1777
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1778 5.6. Q. How do I use mkvalue() to create a tuple of arbitrary length?
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1779
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1780 A. You can't. Use t = newtupleobject(n) instead, and fill it with
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1781 objects using settupleitem(t, i, o) -- note that this "eats" a
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1782 reference count of o. Similar for lists with newlistobject(n) and
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1783 setlistitem(l, i, o). Note that you *must* set all the tuple items to
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1784 some value before you pass the tuple to Python code --
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1785 newtupleobject(n) initializes them to NULL, which isn't a valid Python
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1786 value.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1787
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1788 5.7. Q. How do I call an object's method from C?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1789
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1790 A. Here's a function (untested) that might become part of the next
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1791 release in some form. It uses <stdarg.h> to allow passing the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1792 argument list on to vmkvalue():
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1793
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1794 object *call_method(object *inst, char *methodname, char *format, ...)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1795 {
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1796 object *method;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1797 object *args;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1798 object *result;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1799 va_list va;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1800 method = getattr(inst, methodname);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1801 if (method == NULL) return NULL;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1802 va_start(va, format);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1803 args = vmkvalue(format, va);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1804 va_end(va);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1805 if (args == NULL) {
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1806 DECREF(method);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1807 return NULL;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1808 }
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1809 result = call_object(method, args);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1810 DECREF(method);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1811 DECREF(args);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1812 return result;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1813 }
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1814
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1815 This works for any instance that has methods -- whether built-in or
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1816 user-defined. You are responsible for eventually DECREF'ing the
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1817 return value.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1818
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1819 To call, e.g., a file object's "seek" method with arguments 10, 0
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1820 (assuming the file object pointer is "f"):
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1821
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1822 res = call_method(f, "seek", "(OO)", 10, 0);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1823 if (res == NULL) {
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1824 ... an exception occurred ...
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1825 }
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1826 else {
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1827 DECREF(res);
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1828 }
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1829
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1830 Note that since call_object() *always* wants a tuple for the argument
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1831 list, to call a function without arguments, pass "()" for the format,
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1832 and to call a function with one argument, surround the argument in
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1833 parentheses, e.g. "(i)".
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1834
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1835 5.8. Q. How do I catch the output from print_error()?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1836
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1837 A. (Due to Mark Hammond):
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1838
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1839 * in Python code, define an object that supports the "write()" method.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1840
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1841 * redirect sys.stdout and sys.stderr to this object.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1842
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1843 * call print_error, or just allow the standard traceback mechanism to
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1844 work.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1845
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1846 Then, the output will go wherever your write() method sends it.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1847
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1848 5.9. Q. How do I access a module written in Python from C?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1849
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1850 A. You can get a pointer to the module object as follows:
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1851
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1852 module = import_module("<modulename>");
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1853
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1854 If the module hasn't been imported yet (i.e. it is not yet present in
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1855 sys.modules), this initializes the module; otherwise it simply returns
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1856 the value of sys.modules["<modulename>"]. Note that it doesn't enter
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1857 the module into any namespace -- it only ensures it has been
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1858 initialized and is stored in sys.modules.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1859
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1860 You can then access the module's attributes (i.e. any name defined in
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1861 the module) as follows:
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1862
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1863 attr = getattr(module, "<attrname>");
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1864
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
1865 Calling setattr(), to assign to variables in the module, also works.
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
1866
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1867 5.10. Q. How do I interface to C++ objects from Python?
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1868
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1869 A. Depending on your requirements, there are many approaches. Begin
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1870 by reading the "Extending and Embedding" document (Doc/ext.tex, see
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1871 also <URL:http://www.python.org/doc/>). Realize that for the Python
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1872 run-time system, there isn't a whole lot of difference between C and
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1873 C++ -- so the strategy to build a new Python type around a C structure
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1874 (pointer) type will also work for C++ objects.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1875
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1876 Automatic generation of interfaces between Python and C++ is still at
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1877 the horizon -- parsing C++ header files requires an almost complete
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1878 C++ parser, and many features aren't easily translated from C++ to
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1879 Python: certain forms of operator oveloading, function overloading
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1880 (best approached by a varargs function which explicitly type-checks
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1881 its arguments), and reference arguments are just a number of features
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1882 that are hard to translate correctly if at all.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1883
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1884 The hardest problem is to transparently translate the C++ class
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1885 hierarchy to Python, so that Python programs derive classes from C++
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1886 classes. Given suitable constraints, this may be possible, but it
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1887 would require more space than I have in this FAQ to explain how.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1888 In any case, you can get quite a bit done without this, using just the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1889 existing classes from Python.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1890
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1891 If this all seems rather daunting, that may be because it is -- C++
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1892 isn't exactly a baby to handle without gloves! However, people have
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1893 accomplished amazing feats of interfacing between Python and C++, and
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1894 a detailed question posted to the Python list is likely to elicit some
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1895 interesting and useful responses.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
1896
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1897
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1898 6. Python's design
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1899 ==================
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1900
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1901 6.1. Q. Why isn't there a switch or case statement in Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1902
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1903 A. You can do this easily enough with a sequence of
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1904 if... elif... elif... else. There have been some proposals for switch
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1905 statement syntax, but there is no consensus (yet) on whether and how
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1906 to do range tests.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1907
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1908 6.2. Q. Why does Python use indentation for grouping of statements?
1657
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1909
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1910 A. Basically I believe that using indentation for grouping is
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1911 extremely elegant and contributes a lot to the clarity of the average
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1912 Python program. Most people learn to love this feature after a while.
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1913 Some arguments for it:
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1914
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1915 - Since there are no begin/end brackets there cannot be a disagreement
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1916 between grouping perceived by the parser and the human reader. I
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1917 remember long ago seeing a C fragment like this:
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1918
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1919 if (x <= y)
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1920 x++;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1921 y--;
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
1922 z++;
1657
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1923
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1924 and staring a long time at it wondering why y was being decremented
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1925 even for x > y... (And I wasn't a C newbie then either.)
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1926
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1927 - Since there are no begin/end brackets, Python is much less prone to
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1928 coding-style conflicts. In C there are loads of different ways to
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1929 place the braces (including the choice whether to place braces around
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1930 single statements in certain cases, for consistency). If you're used
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1931 to reading (and writing) code that uses one style, you will feel at
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1932 least slightly uneasy when reading (or being required to write)
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
1933 another style.
1657
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1934
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1935 - Many coding styles place begin/end brackets on a line by themself.
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1936 This makes programs considerably longer and wastes valuable screen
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1937 space, making it harder to get a good overview over a program.
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1938 Ideally, a function should fit on one basic tty screen (say, 20
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1939 lines). 20 lines of Python are worth a LOT more than 20 lines of C.
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1940 This is not solely due to the lack of begin/end brackets (the lack of
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1941 declarations also helps, and the powerful operations of course), but
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1942 it certainly helps!
f02a46754f50 Added stuff about indentation
Guido van Rossum <guido@python.org>
parents: 1613
diff changeset
1943
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1944 6.3. Q. Why are Python strings immutable?
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1945
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1946 A. There are two advantages. One is performance: knowing that a
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1947 string is immutable makes it easy to lay it out at construction time
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1948 -- fixed and unchanging storage requirements. (This is also one of
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
1949 the reasons for the distinction between tuples and lists.) The
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1950 other is that strings in Python are considered as "elemental" as
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1951 numbers. No amount of activity will change the value 8 to anything
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1952 else, and in Python, no amount of activity will change the string
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1953 "eight" to anything else. (Adapted from Jim Roskind)
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1954
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1955 6.4. Q. Why don't strings have methods like index() or sort(), like
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1956 lists?
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1957
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1958 A. Good question. Strings currently don't have methods at all
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1959 (likewise tuples and numbers). Long ago, it seemed unnecessary to
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1960 implement any of these functions in C, so a standard library module
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1961 "string" written in Python was created that performs string related
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1962 operations. Since then, the cry for performance has moved most of
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1963 them into the built-in module strop (this is imported by module
1784
a3f199e8bac6 1.12 -- new address for fu-berlin mirror, infoseek uses python, more
Guido van Rossum <guido@python.org>
parents: 1740
diff changeset
1964 string, which is still the preferred interface, without loss of
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1965 performance except during initialization). Some of these functions
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1966 (e.g. index()) could easily be implemented as string methods instead,
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1967 but others (e.g. sort()) can't, since their interface prescribes that
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1968 they modify the object, while strings are immutable (see the previous
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1969 question).
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1970
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1971 6.5. Q. Why does Python use methods for some functionality
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1972 (e.g. list.index()) but functions for other (e.g. len(list))?
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1973
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1974 A. Functions are used for those operations that are generic for a
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1975 group of types and which should work even for objects that don't have
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1976 methods at all (e.g. numbers, strings, tuples). Also, implementing
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1977 len(), max(), min() as a built-in function is actually less code than
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1978 implementing them as methods for each type. One can quibble about
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1979 individual cases but it's really too late to change such things
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1980 fundamentally now.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1981
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1982 6.6. Q. Why can't I derive a class from built-in types (e.g. lists or
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1983 files)?
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1984
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1985 A. This is caused by the relatively late addition of (user-defined)
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1986 classes to the language -- the implementation framework doesn't easily
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1987 allow it. See the answer to question 4.2 for a work-around. This
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1988 *may* be fixed in the (distant) future.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1989
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
1990 6.7. Q. Why must 'self' be declared and used explicitly in method
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1991 definitions and calls?
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1992
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1993 A. By asking this question you reveal your C++ background. :-)
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1994 When I added classes, this was (again) the simplest way of
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1995 implementing methods without too many changes to the interpreter. I
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1996 borrowed the idea from Modula-3. It turns out to be very useful, for
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1997 a variety of reasons.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1998
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
1999 First, it makes it more obvious that you are using a method or
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2000 instance attribute instead of a local variable. Reading "self.x" or
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2001 "self.meth()" makes it absolutely clear that an instance variable or
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2002 method is used even if you don't know the class definition by heart.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2003 In C++, you can sort of tell by the lack of a local variable
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2004 declaration (assuming globals are rare or easily recognizable) -- but
1740
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2005 in Python, there are no local variable declarations, so you'd have to
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2006 look up the class definition to be sure.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2007
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2008 Second, it means that no special syntax is necessary if you want to
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2009 explicitly reference or call the method from a particular class. In
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2010 C++, if you want to use a method from base class that is overridden in
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2011 a derived class, you have to use the :: operator -- in Python you can
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2012 write baseclass.methodname(self, <argument list>). This is
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2013 particularly useful for __init__() methods, and in general in cases
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2014 where a derived class method wants to extend the base class method of
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2015 the same name and thus has to call the base class method somehow.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2016
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2017 Lastly, for instance variables, it solves a syntactic problem with
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2018 assignment: since local variables in Python are (by definition!) those
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2019 variables to which a value assigned in a function body (and that
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2020 aren't explicitly declared global), there has to be some way to tell
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2021 the interpreter that an assignment was meant to assign to an instance
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2022 variable instead of to a local variable, and it should preferably be
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2023 syntactic (for efficiency reasons). C++ does this through
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2024 declarations, but Python doesn't have declarations and it would be a
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2025 pity having to introduce them just for this purpose. Using the
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2026 explicit "self.var" solves this nicely. Similarly, for using instance
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2027 variables, having to write "self.var" means that references to
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2028 unqualified names inside a method don't have to search the instance's
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2029 directories.
e95b0701c8b5 Version 1.11 -- added several new answers on design questions
Guido van Rossum <guido@python.org>
parents: 1735
diff changeset
2030
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2031 6.8. Q. Can't you emulate threads in the interpreter instead of
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2032 relying on an OS-specific thread implementation?
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2033
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2034 A. Unfortunately, the interpreter pushes at least one C stack frame
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2035 for each Python stack frame. Also, extensions can call back into
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2036 Python at almost random moments. Therefore a complete threads
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2037 implementation requires thread support for C.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2038
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2039 6.9. Q. Why can't lambda forms contain statements?
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2040
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2041 A. Python lambda forms cannot contain statements because Python's
2208
c68a0113b75a intermediate version -- why not...
Guido van Rossum <guido@python.org>
parents: 2048
diff changeset
2042 syntactic framework can't handle statements nested inside expressions.
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2043
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2044 However, in Python, this is not a serious problem. Unlike lambda
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2045 forms in other languages, where they add functionality, Python lambdas
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2046 are only a shorthand notation if you're too lazy to define a function.
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2047
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2048 Functions are already first class objects in Python, and can be
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2049 declared in a local scope. Therefore the only advantage of using a
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2050 lambda form instead of a locally-defined function is that you'll have
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2051 to invent a name for the function -- but that's just a local variable
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2052 to which the function object (which is exactly the same type of object
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2053 that a lambda form yields) is assigned!
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2054
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2055 6.10. Q. Why don't lambdas have access to variables defined in the
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2056 containing scope?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2057
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2058 A. Because they are implemented as ordinary functions.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2059 See question 4.5 above.
4250
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2060
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2061 6.11. Q. Why can't recursive functions be defined inside other functions?
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2062
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2063 A. See question 4.5 above.
4470f7ff0c23 Removed some obsolete questions and references to version 1.2.
Guido van Rossum <guido@python.org>
parents: 4221
diff changeset
2064
1942
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2065 6.12. Q. Why is there no more efficient way of iterating over a dictionary
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2066 than first constructing the list of keys()?
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2067
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2068 A. Have you tried it? I bet it's fast enough for your purposes! In
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2069 most cases such a list takes only a few percent of the space occupied
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2070 by the dictionary -- it needs only 4 bytes (the size of a pointer) per
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2071 key -- a dictionary costs 8 bytes per key plus between 30 and 70
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2072 percent hash table overhead, plus the space for the keys and values --
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2073 by necessity all keys are unique objects and a string object (the most
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2074 common key type) costs at least 18 bytes plus the length of the
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2075 string. Add to that the values contained in the dictionary, and you
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2076 see that 4 bytes more per item really isn't that much more memory...
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2077
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2078 A call to dict.keys() makes one fast scan over the dictionary
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2079 (internally, the iteration function does exist) copying the pointers
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2080 to the key objects into a pre-allocated list object of the right size.
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2081 The iteration time isn't lost (since you'll have to iterate anyway --
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2082 unless in the majority of cases your loop terminates very prematurely
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2083 (which I doubt since you're getting the keys in random order).
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2084
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2085 I don't expose the dictionary iteration operation to Python
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2086 programmers because the dictionary shouldn't be modified during the
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2087 entire iteration -- if it is, there's a very small chance that the
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2088 dictionary is reorganized because the hash table becomes too full, and
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2089 then the iteration may miss some items and see others twice. Exactly
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2090 because this only occurs rarely, it would lead to hidden bugs in
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2091 programs: it's easy never to have it happen during test runs if you
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2092 only insert or delete a few items per iteration -- but your users will
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2093 surely hit upon it sooner or later.
85f1d2bec632 For release 1.1
Guido van Rossum <guido@python.org>
parents: 1903
diff changeset
2094
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2095 6.13. Q. Can Python be compiled to machine code, C or some other language?
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2096
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2097 A. Not easily. Python's high level data types, dynamic typing of
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2098 objects and run-time invocation of the interpreter (using eval() or
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2099 exec) together mean that a "compiled" Python program would probably
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2100 consist mostly of calls into the Python run-time system, even for
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2101 seemingly simple operations like "x+1". Thus, the performance gain
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2102 would probably be minimal.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2103
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2104 Internally, Python source code is always translated into a "virtual
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2105 machine code" or "byte code" representation before it is interpreted
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2106 (by the "Python virtual machine" or "bytecode interpreter"). In order
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2107 to avoid the overhead of parsing and translating modules that rarely
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2108 change over and over again, this byte code is written on a file whose
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2109 name ends in ".pyc" whenever a module is parsed (from a file whose
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2110 name ends in ".py"). When the corresponding .py file is changed, it
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2111 is parsed and translated again and the .pyc file is rewritten. There
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2112 is no performance difference once the .pyc file has been loaded (the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2113 bytecode read from the .pyc file is exactly the same as the bytecode
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2114 created by direct translation). The only difference is that loading
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2115 code from a .pyc file is faster than parsing and translating a .py
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2116 file, so the presence of precompiled .pyc files will generally improve
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2117 start-up time of Python scripts. If desired, the Lib/compileall.py
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2118 module/script can be used to force creation of valid .pyc files for a
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2119 given set of modules.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2120
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2121 If you are looking for a way to translate Python programs in order to
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2122 distribute them in binary form, without the need to distribute the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2123 interpreter and library as well, have a look at the freeze.py script
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2124 in the Tools/freeze directory. This creates a single binary file
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2125 incorporating your program, the Python interpreter, and those parts of
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2126 the Python library that are needed by your program. Of course, the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2127 resulting binary will only run on the same type of platform as that
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2128 used to create it.
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2129
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2130 Hints for proper usage of freeze.py:
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2131
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2132 - the script must be in a file whose name ends in .py
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2133
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2134 - you must have installed Python fully:
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2135
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
2136 make install
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
2137 make libinstall
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
2138 make inclinstall
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
2139 make libainstall
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2140
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2141 6.14. Q. Why doesn't Python use proper garbage collection?
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2142
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2143 A. It's looking less and less likely that Python will ever get
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2144 "automatic" garbage collection (GC). For one thing, unless this were
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2145 added to C as a standard feature, it's a portability pain in the ass.
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2146 And yes, I know about the Xerox library. It has bits of assembler
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2147 code for *most* *common* platforms. Not for all. And although it is
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2148 mostly transparent, it isn't completely transparent (when I once
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2149 linked Python with it, it dumped core).
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2150
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2151 "Proper" GC also becomes a problem when Python gets embedded into
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2152 other applications. While in a stand-alone Python it may be fine to
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2153 replace the standard malloc() and free() with versions provided by the
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2154 GC library, an application embedding Python may want to have its *own*
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2155 substitute for malloc() and free(), and may not want Python's. Right
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2156 now, Python works with anything that implements malloc() and free()
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2157 properly.
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2158
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2159 Besides, the predictability of destructor calls in Python is kind of
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2160 attractive. With GC, the following code (which is fine in current
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2161 Python) will run out of file descriptors long before it runs out of
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2162 memory:
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2163
3207
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
2164 for file in <very long list of files>:
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
2165 f = open(file)
0ed5cd8df51f all sorts of minor nits
Guido van Rossum <guido@python.org>
parents: 3126
diff changeset
2166 c = file.read(1)
3126
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2167
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2168 Using the current reference counting and destructor scheme, each new
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2169 assignment to f closes the previous file. Using GC, this is not
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2170 guaranteed. Sure, you can think of ways to fix this. But it's not
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2171 off-the-shelf technology.
e90643f33c64 +aaron watters, +PSA, +GC, -lance, -beta
Guido van Rossum <guido@python.org>
parents: 3023
diff changeset
2172
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2173
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2174 7. Using Python on non-UNIX platforms
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2175 =====================================
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2176
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
2177 7.1. Q. Is there a Mac version of Python?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2178
2661
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
2179 A. Yes, see the "mac" subdirectory of the distribution sites,
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
2180 e.g. <URL:ftp://ftp.python.org/pub/python/mac/>.
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
2181
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2182 7.2. Q. Are there DOS and Windows versions of Python?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2183
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2184 A. Yes. There is a plethora of not-always-compatible versions. See
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2185 the "pythonwin", "wpy", "nt" and "pc" subdirectories of the
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2186 distribution sites. A quick comparison:
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2187
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2188 PythonWin: Extensive support for the 32-bit native Windows API and GUI
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2189 building using MFC. Windows NT and Windows 95 only (and Windows
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2190 3.1(1) using win32s, until Microsoft stops supporting it :-( ).
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2191 <URL:ftp://ftp.python.org/pub/python/pythonwin/>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2192
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2193 WPY: Ports to DOS, Windows 3.1(1), Windows 95, Windows NT and OS/2.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2194 Also contains a GUI package that offers portability between Windows
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2195 (not DOS) and Unix, and native look and feel on both.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2196 <URL:ftp://ftp.python.org/pub/python/wpy/>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2197
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2198 NT: Basic ports built straight from the 1.4 distribution for Windows
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2199 95 and Windows NT. This will eventually provide core support for
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2200 both PythonWin and WPY on all 32-bit Microsoft platforms.
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
2201 <URL:ftp://ftp.python.org/pub/python/nt/>.
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
2202
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2203 PC: Old, unsupported ports to DOS, Windows 3.1(1) and OS/2.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2204 <URL:ftp://ftp.python.org/pub/python/pc/>.
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2205
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2206 7.3. Q. Is there an OS/2 version of Python?
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2207
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2208 A. Yes, see the "pc" and "wpy" subdirectory of the distribution sites
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2209 (see above).
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2210
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2211 7.4. Q. Is there a VMS version of Python?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2212
2855
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
2213 A. Donn Cave <donn@cac.washington.edu> did a partial port. The
e6bec149a8d7 new version
Guido van Rossum <guido@python.org>
parents: 2716
diff changeset
2214 results of his efforts are on public display in
3018
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
2215 <<URL:ftp://ftp.python.org/pub/python/contrib/vms.tar.gz/>. Someone
27390b536640 new stuff
Guido van Rossum <guido@python.org>
parents: 2855
diff changeset
2216 else is working on a more complete port, for details watch the list.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2217
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2218 7.5. Q. What about IBM mainframes, or other non-UNIX platforms?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2219
3023
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2220 A. I haven't heard about these, except I remember hearing about an
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2221 OS/9 port and a port to Vxworks (both operating systems for embedded
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2222 systems). If you're interested in any of this, go directly to the
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2223 newsgroup and ask there, you may find exactly what you need. For
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2224 example, a port to MPE/iX 5.0 on HP3000 computers was just announced,
87847228b158 several new questions, 1.3 beta mentioned
Guido van Rossum <guido@python.org>
parents: 3018
diff changeset
2225 see <URL:http://www.allegro.com/software/>.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2226
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2227 7.6. Q. Where are the source or Makefiles for the non-UNIX versions?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2228
2661
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
2229 A. The standard sources can (almost) be used. Additional sources can
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
2230 be found in the platform-specific subdirectories of the distribution.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2231
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2232 7.7. Q. What is the status and support for the non-UNIX versions?
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2233
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2234 A. I don't have access to most of these platforms, so in general I am
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2235 dependent on material submitted by volunteers(*). However I strive to
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2236 integrate all changes needed to get it to compile on a particular
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2237 platform back into the standard sources, so porting of the next
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2238 version to the various non-UNIX platforms should be easy.
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2239
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
2240 (*) For the Macintosh, that volunteer is me, with help from Jack
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
2241 Jansen <jack@cwi.nl>.
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2242
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2243 7.8. Q. I have a PC version but it appears to be only a binary.
1663
a6e6fad1a01b Version 1.9
Guido van Rossum <guido@python.org>
parents: 1657
diff changeset
2244 Where's the library?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2245
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2246 A. You still need to copy the files from the distribution directory
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
2247 "python/Lib" to your system. If you don't have the full distribution,
2661
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
2248 you can get the file lib<version>.tar.gz from most ftp sites carrying
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
2249 Python; this is a subset of the distribution containing just those
2716
19b1195a3af8 next version; python.org changes
Guido van Rossum <guido@python.org>
parents: 2661
diff changeset
2250 files, e.g. <URL:ftp://ftp.python.org/pub/python/src/lib1.1.tar.gz>.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2251
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2252 Once you have installed the library, you need to point sys.path to it.
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2253 Assuming the library is in C:\misc\python\lib, the following commands
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2254 will point your Python interpreter to it (note the doubled backslashes
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2255 -- you can also use single forward slashes instead):
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2256
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
2257 >>> import sys
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
2258 >>> sys.path.insert(0, 'C:\\misc\\python\\lib')
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
2259 >>>
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2260
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2261 For a more permanent effect, set the environment variable PYTHONPATH,
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2262 as follows (talking to a DOS prompt):
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2263
2048
c85abcc752b1 Posted as 1.18
Guido van Rossum <guido@python.org>
parents: 2012
diff changeset
2264 C> SET PYTHONPATH=C:\misc\python\lib
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2265
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2266 7.9. Q. Where's the documentation for the Mac or PC version?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2267
2661
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
2268 A. The documentation for the Unix version also applies to the Mac and
b4fd48e3a3b8 changed path references
Guido van Rossum <guido@python.org>
parents: 2660
diff changeset
2269 PC versions. Where applicable, differences are indicated in the text.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2270
4278
f6e824b27032 Rewrite sections on GUI and DOS/Windows, various other small edits,
Guido van Rossum <guido@python.org>
parents: 4250
diff changeset
2271 7.10. Q. The Mac (PC) version doesn't seem to have any facilities for
1547
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
2272 creating or editing programs apart from entering it interactively, and
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
2273 there seems to be no way to save code that was entered interactively.
0efa240b1dbc At the release of 1.0.1
Guido van Rossum <guido@python.org>
parents: 1541
diff changeset
2274 How do I create a Python program on the Mac (PC)?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2275
1903
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2276 A. Use an external editor. On the Mac, BBEdit seems to be a popular
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2277 no-frills text editor. I work like this: start the interpreter; edit
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2278 a module file using BBedit; import and test it in the interpreter;
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2279 edit again in BBedit; then use the built-in function reload() to
e450bd43631a New version: 1.14 (previous oine was misnumbered 1.12).
Guido van Rossum <guido@python.org>
parents: 1902
diff changeset
2280 re-read the imported module; etc.
1579
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2281
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2282 Regarding the same question for the PC, Kurt Wm. Hemr writes: "While
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2283 anyone with a pulse could certainly figure out how to do the same on
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2284 MS-Windows, I would recommend the NotGNU Emacs clone for MS-Windows.
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2285 Not only can you easily resave and "reload()" from Python after making
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2286 changes, but since WinNot auto-copies to the clipboard any text you
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2287 select, you can simply select the entire procedure (function) which
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2288 you changed in WinNot, switch to QWPython, and shift-ins to reenter
021daabe69d8 Updated for existence of newsgroup and various misc things
Guido van Rossum <guido@python.org>
parents: 1547
diff changeset
2289 the changed program unit."