1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
|
Subject: FAQ: Python -- an object-oriented language
Newsgroups: comp.lang.python,comp.answers,news.answers
Followup-to: comp.lang.python
From: guido@cwi.nl (Guido van Rossum)
Reply-to: guido@cwi.nl (Guido van Rossum)
Approved: news-answers-request@MIT.Edu
Archive-name: python-faq/part1
Version: 1.8
Last-modified: 15 May 1994
This article contains answers to Frequently Asked Questions about
Python (an object-oriented interpreted programming language -- see
the answer to question 1.1 for a short overview).
Copyright 1993, 1994 Guido van Rossum. Unchanged electronic
redistribution of this FAQ is allowed. Printed redistribution only
with permission of the author. No warranties.
Author's address:
Guido van Rossum
CWI, dept. CST
Kruislaan 413
P.O. Box 94079
1090 GB Amsterdam
The Netherlands
Email: guido@cwi.nl
The latest version of this FAQ is available by anonymous ftp from
ftp.cwi.nl [192.16.184.180] in the directory /pub/python, with
filename python-FAQ. It will also be posted regularly to the
newsgroups comp.answers and comp.lang.python.
Many FAQs, including this one, are available by anonymous ftp from
rtfm.mit.edu [18.70.0.209] in the directory pub/usenet/news.answers.
The name under which a FAQ is archived appears in the Archive-name line
at the top of the article. This FAQ is archived as python-faq/part1.
There's a mail server on that machine which will send you files from
the archive by e-mail if you have no ftp access. You send a e-mail
message to mail-server@rtfm.mit.edu containing the single word help in
the message body to receive instructions.
This FAQ is divided in the following chapters:
1. General information and availability
2. Python in the real world
3. Building Python
4. Programming in Python
5. Extending Python
6. Python's design
7. Using Python on non-UNIX platforms
To find the start of a particular chapter, search for the chapter number
followed by a dot and a space at the beginning of a line (e.g. to
find chapter 4 in vi, type /^4\. /).
Here's an overview of the questions per chapter:
1. General information and availability
1.1. Q. What is Python?
1.2. Q. Why is it called Python?
1.3. Q. How do I obtain a copy of the Python source?
1.4. Q. How do I get documentation on Python?
1.5. Q. Are there other ftp sites that mirror the Python distribution?
1.6. Q. Is there a newsgroup or mailing list devoted to Python?
1.7. Q. Is there a book on Python, or will there be one out soon?
1.8. Q. Are there any published articles about Python that I can quote?
1.9. Q. How does the Python version numbering scheme work?
1.10. Q. Are there other ftp sites that carry Python related material?
2. Python in the real world
2.1. Q. How many people are using Python?
2.2. Q. Have any significant projects been done in Python?
2.3. Q. Are there any commercial projects going on using Python?
2.4. Q. How stable is Python?
2.5. Q. What new developments are expected for Python in the future?
3. Building Python
3.1. Q. Is there a test set?
3.2. Q. When running the test set, I get complaints about floating point
operations, but when playing with floating point operations I cannot
find anything wrong with them.
3.3. Q. Link errors building Python with STDWIN on SGI IRIX.
3.4. Q. Link errors after rerunning the configure script.
3.5. Q. The python interpreter complains about options passed to a
script (after the script name).
3.6. Q. When building on the SGI, make tries to run python to create
glmodule.c, but python hasn't been built or installed yet.
3.7. Q. Other trouble building Python 1.0.2 on platform X.
4. Programming in Python
4.1. Q. Is there a source code level debugger with breakpoints, step,
etc.?
4.2. Q. Can I create an object class with some methods implemented in
C and others in Python (e.g. through inheritance)? (Also phrased as:
Can I use a built-in type as base class?)
4.3. Q. Is there a curses/termcap package for Python?
4.4. Q. Is there an equivalent to C's onexit() in Python?
4.5. Q. When I define a function nested inside another function, the
nested function seemingly can't access the local variables of the
outer function. What is going on? How do I pass local data to a
nested function?
4.6. Q. How do I iterate over a sequence in reverse order?
4.7. Q. My program is too slow. How do I speed it up?
4.8. Q. When I have imported a module, then edit it, and import it
again (into the same Python process), the changes don't seem to take
place. What is going on?
4.9. Q. I have a module in which I want to execute some extra code when it
is run as a script. How do I find out whether I am running as a
script?
5. Extending Python
5.1. Q. Can I create my own functions in C?
5.2. Q. Can I create my own functions in C++?
6. Python's design
6.1. Q. Why isn't there a generic copying operation for objects in
Python?
6.2. Q. Why isn't there a generic way to implement persistent objects
in Python? (Persistent == automatically saved to and restored from
disk.)
6.3. Q. Why isn't there a switch or case statement in Python?
6.4. Q. Why does Python use indentation for grouping of statements?
7. Using Python on non-UNIX platforms
7.1. Q. Is there a Mac version of Python?
7.2. Q. Is there a DOS version of Python?
7.3. Q. Is there a Windows version of Python?
7.4. Q. Is there a Windows NT version of Python?
7.5. Q. I have the DOS or Windows version but it appears to be only a
binary. Where's the library?
7.6. Q. Where's the documentation for the Mac or PC version?
7.7. Q. The Mac (PC) version doesn't seem to have any facilities for
creating or editing programs apart from entering it interactively, and
there seems to be no way to save code that was entered interactively.
How do I create a Python program on the Mac (PC)?
To find a particular question, search for the question number followed
by a dot, a space, and a Q at the beginning of a line (e.g. to find
question 4.2 in vi, type /^4\.2\. Q/).
1. General information and availability
=======================================
1.1. Q. What is Python?
A. Python is an interpreted, interactive, object-oriented programming
language. It incorporates modules, exceptions, dynamic typing, very
high level dynamic data types, and classes. Python combines
remarkable power with very clear syntax. It has interfaces to many
system calls and libraries, as well as to various window systems, and
is extensible in C or C++. It is also usable as an extension language
for applications that need a programmable interface. Finally, Python
is portable: it runs on many brands of UNIX, on the Mac, and on
MS-DOS.
To find out more, the best thing to do is to start reading the
tutorial from the documentation set (see a few questions further
down).
1.2. Q. Why is it called Python?
A. Apart from being a computer wizard, I'm also a fan of "Monty
Python's Flying Circus" (a BBC comedy series from the seventies, in
the -- unlikely -- case you didn't know). It occurred to me one day
that I needed a name that was short, unique, and slightly mysterious.
And I happened to be reading some scripts from the series at the
time... So then I decided to call my language Python. But Python is
not a joke. And don't you associate it with dangerous reptiles
either!
1.3. Q. How do I obtain a copy of the Python source?
A. The latest Python source distribution is always available by
anonymous ftp from ftp.cwi.nl [192.16.184.180] in the directory
/pub/python, with filename python<version>.tar.gz. (Old versions may
have an extension of .Z, indicating use of "compress" compression.)
It is a gzip'ed tar file containing the complete C source, LaTeX
documentation, Python library modules, example programs, and several
useful pieces of freely distributable software. This will compile and
run out of the box on most UNIX platforms. At the time of writing,
<version> is 1.0.2. (See section 7 for non-UNIX information.)
1.4. Q. How do I get documentation on Python?
A. The latest Python documentation set is always available by
anonymous ftp from ftp.cwi.nl [192.16.184.180] in the directory
/pub/python, with filename pythondoc-ps<version>.tar.gz. It is a
gzip'ed tar file containing PostScript files of the reference manual,
the library manual, and the tutorial. At the time of writing
<version> is 1.0.2. Note that the library manual is the most
important one of the set, as much of Python's power stems from the
standard or built-in types, functions and modules, all of which are
described here. PostScript for a high-level description of Python is
in the file nluug-paper.ps.
1.5. Q. Are there other ftp sites that mirror the Python distribution?
A. The following sites keep mirrors of the Python distribution:
Site IP address Directory
gatekeeper.dec.com 16.1.0.2 /pub/plan/python/cwi
ftp.uu.net 192.48.96.9 /languages/python
ftp.wustl.edu 128.252.135.4 /graphics/graphics/sgi-stuff/python
ftp.funet.fi 128.214.6.100 /pub/languages/python
ftp.fu-berlin.de 130.133.4.50 /pub/unix/languages/python (*python* only)
ftp.sunet.se 130.238.127.3 /pub/lang/python
Or try archie on e.g. python1.0 to locate the nearest copy of that
version...
1.6. Q. Is there a newsgroup or mailing list devoted to Python?
A. There is a newsgroup, comp.lang.python, and a mailing list. The
newsgroup and mailing list are gatewayed into each other -- if you can
read news it is not necessary to subscribe to the mailing list. Send
e-mail to python-list-request@cwi.nl to (un)subscribe to the mailing
list.
1.7. Q. Is there a book on Python, or will there be one out soon?
A. Unfortunately, not yet. I would like to write one but my
obligations at CWI include too much other work to make much progress
on it. Several parties have expressed interest in sponsoring or
helping the production of a book or reference manual, but so far there
are no firm plans. If you volunteer help, by all means drop me a
note!
1.8. Q. Are there any published articles about Python that I can quote?
A. So far the only refereed and published article that describes
Python in some detail is:
Guido van Rossum and Jelke de Boer, "Interactively Testing Remote
Servers Using the Python Programming Language", CWI Quarterly, Volume
4, Issue 4 (December 1991), Amsterdam, pp 283-303.
LaTeX source for this paper is available as part of the Python source
distribution.
A more recent high-level description of Python is:
Guido van Rossum, "An Introduction to Python for UNIX/C
Programmers", in the proceedings of the NLUUG najaarsconferentie
1993 (dutch UNIX users group meeting november 1993).
PostScript for this paper and for the slides used for the accompanying
presentation can be found in the ftp directory mentioned a few
questions earlier, with filenames nluug-paper.ps and nluug-slides.ps,
respectively.
1.9. Q. How does the Python version numbering scheme work?
A. Python versions are numbered A.B.C. A is the major version number
-- it is only incremented for major changes in functionality or source
structure. B is the minor version number, incremented for less
earth-shattering changes to a release. C is the patchlevel -- it is
incremented for each new release. Note that in the past, patches have
added significant changes; in fact the changeover from 0.9.9 to 1.0.0
was the first time that either A or B changed!
1.10. Q. Are there other ftp sites that carry Python related material?
A. An interesting ftp site for Python users is ftp.markv.com
(192.122.251.1); the directory pub/python contains a growing
collection of interesting Python scripts. To submit a script for
inclusion, place it together with a readme file (with extension
.readme) in the publicly writable directory /incoming/python. This
service is maintained by Lance Ellinghouse <lance@markv.com>.
2. Python in the real world
===========================
2.1. Q. How many people are using Python?
A. I don't know, but the maximum number of simultaneous subscriptions
to the Python mailing list before it was gatewayed into the newsgroup
was about 180 (several of which were local redistribution lists). I
believe that many active Python users don't bother to subscribe to the
list, and now that there's a newsgroup the mailing list subscription
is even less meaningful.
2.2. Q. Have any significant projects been done in Python?
A. Here at CWI (the home of Python), we have written a 20,000 line
authoring environment for transportable hypermedia presentations, a
5,000 line multimedia teleconferencing tool, as well as many many
smaller programs.
The University of Virginia uses Python to control a virtual reality
engine. Contact: Matt Conway <conway@virginia.edu>.
See also the next question.
2.3. Q. Are there any commercial projects going on using Python?
A. Several companies have revealed to me that they are planning or
considering to use Python in a future product. The furthest is
Sunrise Software, who already have a product out using Python -- they
use Python for a GUI management application and an SNMP network
manangement application. Contact: <info@sunrise.com>.
Individuals at many other companies are using Python for
internal development (witness their contributions to the Python
mailing list or newsgroup).
Python has also been elected as an extension language by MADE, a
consortium supported by the European Committee's ESPRIT program and
consisting of Bull, CWI and some other European companies. Contact:
Ivan Herman <ivan@cwi.nl>.
2.4. Q. How stable is Python?
A. Very stable. While the current version number (1.0.2) would
suggest it is in the early stages of development, in fact new, stable
releases (numbered 0.9.x) have been coming out roughly every 3 to 6
months for the past four years.
2.5. Q. What new developments are expected for Python in the future?
A. Without warranty that any of this will actually be realized: I am
currently thinking about mechanisms for built-in on-line help and a
switch/case statement. There have been some discussions on
hierarchical module names which might solve the problem of the
development of large packages. A pthreads interface has been
contributed which I would like to merge into the latest release. The
X interface needs improving. There are also some people
(independently) working on a windowing interface based on STDWIN but
with the power and ease of use of the average modern widget set. I
still hope to get some help in producing a Windows version. It would
be nice if there were a window-based class browser (Someone at CWI has
contributed one using Motif but it needs some work). Also: improved
support for embedding Python in other applications, e.g. by renaming
most global symbols to have a "Py" prefix and providing more
documentation and threading support.
3. Building Python
==================
3.1. Q. Is there a test set?
A. Yes, simply do "import testall" (or "import autotest" if you aren't
interested in the output). The standard modules whose name begins
with "test" together comprise the test. The test set doesn't test
*all* features of Python but it goes a long way to confirm that a new
port is actually working. The Makefile contains an entry "make test"
which runs the autotest module.
3.2. Q. When running the test set, I get complaints about floating point
operations, but when playing with floating point operations I cannot
find anything wrong with them.
A. The test set makes occasional unwarranted assumptions about the
semantics of C floating point operations. Until someone donates a
better floating point test set, you will have to comment out the
offending floating point tests and execute similar tests manually.
3.3. Q. Link errors building Python with STDWIN on SGI IRIX.
A. Rebuild STDWIN, specifying "CC=cc -cckr" in the Makefile.
3.4. Q. Link errors after rerunning the configure script.
A. It is generally necessary to run "make clean" after a configuration
change.
3.5. Q. The python interpreter complains about options passed to a
script (after the script name).
A. You are probably linking with GNU getopt, e.g. through -liberty.
Don't. (If you are using this because you link with -lreadline, use
the readline distributed with Python instead.)
3.6. Q. When building on the SGI, make tries to run python to create
glmodule.c, but python hasn't been built or installed yet.
A. Comment out the line mentioning glmodule.c in Setup and build a
python without gl first; install it or make sure it is in your $PATH,
then edit the Setup file again to turn on the gl module, and make
again. You don't need to do "make clean"; you do need to run "make
Makefile" in the Modules subdirectory (or just run "make" at the
toplevel).
3.7. Q. Other trouble building Python 1.0.2 on platform X.
A. Please email the details to <guido@cwi.nl> and I'll look into it.
4. Programming in Python
========================
4.1. Q. Is there a source code level debugger with breakpoints, step,
etc.?
A. Yes. Check out module pdb; pdb.help() prints the documentation (or
you can read it as Lib/pdb.doc). If you use the STDWIN option,
there's also a windowing interface, wdb. You can write your own
debugger by using the code for pdb or wdb as an example.
4.2. Q. Can I create an object class with some methods implemented in
C and others in Python (e.g. through inheritance)? (Also phrased as:
Can I use a built-in type as base class?)
A. No, but you can easily create a Python class which serves as a
wrapper around a built-in object, e.g. (for dictionaries):
# A user-defined class behaving almost identical
# to a built-in dictionary.
class UserDict:
def __init__(self): self.data = {}
def __repr__(self): return repr(self.data)
def __cmp__(self, dict):
if type(dict) == type(self.data):
return cmp(self.data, dict)
else:
return cmp(self.data, dict.data)
def __len__(self): return len(self.data)
def __getitem__(self, key): return self.data[key]
def __setitem__(self, key, item): self.data[key] = item
def __delitem__(self, key): del self.data[key]
def keys(self): return self.data.keys()
def items(self): return self.data.items()
def values(self): return self.data.values()
def has_key(self, key): return self.data.has_key(key)
4.3. Q. Is there a curses/termcap package for Python?
A. No, but you can use the "alfa" (== character cell) version of
STDWIN. (STDWIN == Standard Windows, a portable windowing system
interface by the same author, URL: ftp://ftp.cwi.nl/pub/stdwin.)
This will also prepare your program for porting to windowing
environments such as X11 or the Macintosh.
4.4. Q. Is there an equivalent to C's onexit() in Python?
A. Yes, if you import sys and assign a function to sys.exitfunc, it
will be called when your program exits, is killed by an unhandled
exception, or (on UNIX) receives a SIGHUP or SIGTERM signal.
4.5. Q. When I define a function nested inside another function, the
nested function seemingly can't access the local variables of the
outer function. What is going on? How do I pass local data to a
nested function?
A. Python does not have arbitrarily nested scopes. When you need to
create a function that needs to access some data which you have
available locally, create a new class to hold the data and return a
method of an instance of that class, e.g.:
class MultiplierClass:
def __init__(self, factor):
self.factor = factor
def multiplier(self, argument):
return argument * self.factor
def generate_multiplier(factor):
return MultiplierClass(factor).multiplier
twice = generate_multiplier(2)
print twice(10)
# Output: 20
4.6. Q. How do I iterate over a sequence in reverse order?
A. If it is a list, the fastest solution is
list.reverse()
try:
for x in list:
"do something with x"
finally:
list.reverse()
This has the disadvantage that while you are in the loop, the list
is temporarily reversed. If you don't like this, you can make a copy.
This appears expensive but is actually faster than other solutions:
rev = list[:]
rev.reverse()
for x in rev:
<do something with x>
If it isn't a list, a more general but slower solution is:
i = len(list)
while i > 0:
i = i-1
x = list[i]
<do something with x>
A more elegant solution, is to define a class which acts as a sequence
and yields the elements in reverse order (solution due to Steve
Majewski):
class Rev:
def __init__(self, seq):
self.forw = seq
def __len__(self):
return len(self.forw)
def __getitem__(self, i):
return self.forw[-(i + 1)]
You can now simply write:
for x in Rev(list):
<do something with x>
Unfortunately, this solution is slowest of all, due the the method
call overhead...
4.7. Q. My program is too slow. How do I speed it up?
A. That's a tough one, in general. There are many tricks to speed up
Python code; I would consider rewriting parts in C only as a last
resort. One thing to notice is that function and (especially) method
calls are rather expensive; if you have designed a purely OO interface
with lots of tiny functions that don't do much more than get or set an
instance variable or call another method, you may consider using a
more direct way, e.g. directly accessing instance variables. Also see
the standard module "profile" (described in the file
"python/lib/profile.doc") which makes it possible to find out where
your program is spending most of its time (if you have some patience
-- the profiling itself can slow your program down by an order of
magnitude).
4.8. Q. When I have imported a module, then edit it, and import it
again (into the same Python process), the changes don't seem to take
place. What is going on?
A. For efficiency reasons, Python only reads the module file on the
first time a module is imported (otherwise a program consisting of
many modules, each of which imports the same basic module, would read
the basic module over and over again). To force a changed module
being read again, do this:
import modname
reload(modname)
Warning: this technique is not 100% fool-proof. In particular,
modules containing statements like
from modname import some_objects
will continue to work with the old version of the objects imported
thus.
4.9. Q. I have a module in which I want to execute some extra code when it
is run as a script. How do I find out whether I am running as a
script?
A. A module can find out its own module name by alooking at the
(predefined) global variable __name__. If this has the value
'__main__' you are running as a script. E.g. if you put the following
on the last line of your module, main() is called only when your
module is running as a script:
if __name__ == '__main__': main()
5. Extending Python
===================
5.1. Q. Can I create my own functions in C?
A. Yes, you can create built-in modules containing functions,
variables, exceptions and even new types in C. This is explained in
the document "Extending and Embedding the Python Interpreter" (the
LaTeX file Doc/ext.tex). Also read the chapter on dynamic loading.
5.2. Q. Can I create my own functions in C++?
A. Yes, using the C-compatibility features found in C++. Basically
you place extern "C" { ... } around the Python include files and put
extern "C" before each function that is going to be called by the
Python interpreter. Global or static C++ objects with constructors
are probably not a good idea.
6. Python's design
==================
6.1. Q. Why isn't there a generic copying operation for objects in
Python?
A. Hmm. Maybe there should be one, but it's difficult to assign a
useful meaning to copying of open files, sockets and windows, or
recursive data structures. As long as you design all your classes
yourself you are of course free to define a standard base class that
defines an overridable copying operation for all the objects you care
about. (One practical point: it would have to be a built-in function,
not a standard method name, since not all built-in object types have
methods; e.g. strings, integers and tuples don't.)
6.2. Q. Why isn't there a generic way to implement persistent objects
in Python? (Persistent == automatically saved to and restored from
disk.)
A. Hmm, hmm. Basically for the same reasons as why there is no
generic copying operation.
6.3. Q. Why isn't there a switch or case statement in Python?
A. You can do this easily enough with a sequence of
if... elif... elif... else. There have been some proposals for switch
statement syntax, but there is no concensus (yet) on whether and how
to do range tests.
6.4. Q. Why does Python use indentation for grouping of statements?
A. Basically I believe that using indentation for grouping is
extremely elegant and contributes a lot to the clarity of the average
Python program. Most people learn to love this feature after a while.
Some arguments for it:
- Since there are no begin/end brackets there cannot be a disagreement
between grouping perceived by the parser and the human reader. I
remember long ago seeing a C fragment like this:
if (x <= y)
x++;
y--;
z++;
and staring a long time at it wondering why y was being decremented
even for x > y... (And I wasn't a C newbie then either.)
- Since there are no begin/end brackets there can be no conflicting
coding styles. In C there are loads of different ways to place the
braces (including the choice whether to place braces around single
statements in certain cases, for consistency). If you're used to
reading (and writing) code that uses one style, you will feel at least
slightly uneasy when reading (or being required to write) another
style.
- Many coding styles place begin/end brackets on a line by themself.
This makes programs considerably longer and wastes valuable screen
space, making it harder to get a good overview over a program.
Ideally, a function should fit on one basic tty screen (say, 20
lines). 20 lines of Python are worth a LOT more than 20 lines of C.
This is not solely due to the lack of begin/end brackets (the lack of
declarations also helps, and the powerful operations of course), but
it certainly helps!
7. Using Python on non-UNIX platforms
=====================================
7.1. Q. Is there a Mac version of Python?
A. Yes. It is on most ftp sites carrying Python as python.sea.hqx --
this is a self-extracting archive containing the application binary as
well as the Lib modules.
7.2. Q. Is there a DOS version of Python?
A. Yes. More than one, actually: 16python.exe runs in standard DOS
mode on 186 CPUs or higher; 32python.exe uses a DOS extender and only
runs on a 386 or higher CPUs. Although 16python.exe does not pass the
test set because test_grammar is too big for the parser, it actually
has about 270 kbyte of allocatable heap space, which is sufficient for
fairly large programs. 32python.exe is distributed as a tar file
containing the required DOS extended and 387 emulator. Both are on
most ftp sites carrying Python.
7.3. Q. Is there a Windows version of Python?
A. Yes. Use qwpython.exe. The only problem with it: ^C
unconditionally kills the entire program -- it does not raise
KeyboardInterrupt. You can also run 16python.exe or 32python.exe in a
"DOS box", but qwpython.exe appears to be slightly faster.
7.4. Q. Is there a Windows NT version of Python?
A. Yes. Use ntpython.exe. This is for Intel CPUs. If you want a
Windows user interface, use qwpython.exe.
7.5. Q. I have the DOS or Windows version but it appears to be only a
binary. Where's the library?
A. You still need to copy the files from the distribution directory
"python/Lib" to your system. If you don't have the full distribution,
you can get the file pythonlib1.0.2.tar.gz from most ftp sites carrying
Python; this is a subset of the distribution containing just those
file.
Once you have installed the library, you need to point sys.path to it.
Assuming the library is in C:\misc\python\lib, the following commands
will point your Python interpreter to it (note the doubled backslashes
-- you can also use single forward slashes instead):
>>> import sys
>>> sys.path.insert(0, 'C:\\misc\\python\\lib')
>>>
For a more permanent effect, set the environment variable PYTHONPATH,
as follows (talking to a DOS prompt):
C> SET PYTHONPATH=C:\misc\python\lib
7.6. Q. Where's the documentation for the Mac or PC version?
A. There isn't any. The documentation for the Unix version also
applies to the Mac and PC versions. Where applicable, differences
are indicated in the text.
7.7. Q. The Mac (PC) version doesn't seem to have any facilities for
creating or editing programs apart from entering it interactively, and
there seems to be no way to save code that was entered interactively.
How do I create a Python program on the Mac (PC)?
A. Use an external editor. On the Mac, I am quite happy with the Desk
Accessory called Sigma Edit; this doesn't require Multifinder or
System 7. I work like this: start the interpreter; edit a module file
using Sigma Edit; import and test it in the interpreter; edit again in
Sigma Edit; then use the built-in function reload() to re-read the
imported module; etc.
Regarding the same question for the PC, Kurt Wm. Hemr writes: "While
anyone with a pulse could certainly figure out how to do the same on
MS-Windows, I would recommend the NotGNU Emacs clone for MS-Windows.
Not only can you easily resave and "reload()" from Python after making
changes, but since WinNot auto-copies to the clipboard any text you
select, you can simply select the entire procedure (function) which
you changed in WinNot, switch to QWPython, and shift-ins to reenter
the changed program unit."
|