6677
88Archive-name: python-faq/part1
9- Version: 1.10
10- Last-modified: 14 July 1994
9+ Version: 1.11
10+ Last-modified: 25 July 1994
1111
1212This article contains answers to Frequently Asked Questions about
1313Python (an object-oriented interpreted programming language -- see
@@ -76,6 +76,7 @@ Here's an overview of the questions per chapter:
7676 2.3. Q. Are there any commercial projects going on using Python?
7777 2.4. Q. How stable is Python?
7878 2.5. Q. What new developments are expected for Python in the future?
79+ 2.6. Q. Is it reasonable to propose incompatible changes to Python?
7980
8081 3. Building Python
8182 3.1. Q. Is there a test set?
@@ -88,7 +89,8 @@ Here's an overview of the questions per chapter:
8889 script (after the script name).
8990 3.6. Q. When building on the SGI, make tries to run python to create
9091 glmodule.c, but python hasn't been built or installed yet.
91- 3.7. Q. Other trouble building Python 1.0.2 on platform X.
92+ 3.7. Q. Python built with gcc for the DEC Alpha doesn't work.
93+ 3.8. Q. Other trouble building Python on platform X.
9294
9395 4. Programming in Python
9496 4.1. Q. Is there a source code level debugger with breakpoints, step,
@@ -131,6 +133,15 @@ Here's an overview of the questions per chapter:
131133 disk.)
132134 6.3. Q. Why isn't there a switch or case statement in Python?
133135 6.4. Q. Why does Python use indentation for grouping of statements?
136+ 6.5. Q. Why are Python strings immutable?
137+ 6.6. Q. Why don't strings have methods like index() or sort(), like
138+ lists?
139+ 6.7. Q. Why does Python use methods for some functionality
140+ (e.g. list.index()) but functions for other (e.g. len(list))?
141+ 6.8. Q. Why can't I derive a class from built-in types (e.g. lists or
142+ files)?
143+ 6.9. Q. Why must 'self' be declared and used explicitly in method
144+ definitions and calls?
134145
135146 7. Using Python on non-UNIX platforms
136147 7.1. Q. Is there a Mac version of Python?
@@ -190,21 +201,20 @@ have an extension of .Z, indicating use of "compress" compression.)
190201It is a gzip'ed tar file containing the complete C source, LaTeX
191202documentation, Python library modules, example programs, and several
192203useful pieces of freely distributable software. This will compile and
193- run out of the box on most UNIX platforms. At the time of writing,
194- <version> is 1.0.2. (See section 7 for non-UNIX information.)
204+ run out of the box on most UNIX platforms. (See section 7 for
205+ non-UNIX information.)
195206
1962071.4. Q. How do I get documentation on Python?
197208
198209A. The latest Python documentation set is always available by
199210anonymous ftp from ftp.cwi.nl [192.16.191.128] in the directory
200211/pub/python, with filename pythondoc-ps<version>.tar.gz. It is a
201212gzip'ed tar file containing PostScript files of the reference manual,
202- the library manual, and the tutorial. At the time of writing
203- <version> is 1.0.2. Note that the library manual is the most
204- important one of the set, as much of Python's power stems from the
205- standard or built-in types, functions and modules, all of which are
206- described here. PostScript for a high-level description of Python is
207- in the file nluug-paper.ps.
213+ the library manual, and the tutorial. Note that the library manual is
214+ the most important one of the set, as much of Python's power stems
215+ from the standard or built-in types, functions and modules, all of
216+ which are described here. PostScript for a high-level description of
217+ Python is in the file nluug-paper.ps.
208218
2092191.5. Q. Are there other ftp sites that mirror the Python distribution?
210220
335345
3363462.4. Q. How stable is Python?
337347
338- A. Very stable. While the current version number (1.0.2) would
339- suggest it is in the early stages of development, in fact new, stable
340- releases (numbered 0.9.x) have been coming out roughly every 3 to 6
348+ A. Very stable. While the current version number would suggest it is
349+ in the early stages of development, in fact new, stable releases
350+ (numbered 0.9.x and 1.0 .x) have been coming out roughly every 3 to 6
341351months for the past four years.
342352
3433532.5. Q. What new developments are expected for Python in the future?
@@ -361,6 +371,15 @@ Also planned is improved support for embedding Python in other
361371applications, e.g. by renaming most global symbols to have a "Py"
362372prefix and providing more documentation and threading support.
363373
374+ 2.6. Q. Is it reasonable to propose incompatible changes to Python?
375+
376+ A. In general, no. There are already millions of lines of Python code
377+ around the world, so any changes in the language that invalidates more
378+ than a very small fraction of existing programs has to be frowned
379+ upon. Even if you can provide a conversion program, there still is
380+ the problem of updating all documentation. Providing a gradual
381+ upgrade path is the only way if a feature has to be changed.
382+
364383
3653843. Building Python
366385==================
@@ -409,7 +428,15 @@ again. You don't need to do "make clean"; you do need to run "make
409428Makefile" in the Modules subdirectory (or just run "make" at the
410429toplevel).
411430
412- 3.7. Q. Other trouble building Python 1.0.2 on platform X.
431+ 3.7. Q. Python built with gcc for the DEC Alpha doesn't work.
432+
433+ People have reported problems with both gcc 2.5.8 and 2.6.0. The DEC
434+ OSF/1 cc compiler does not have these problems so it's probably gcc's
435+ fault. One person reported that the problem went away when using -g
436+ instead of -O so this may be an option if you insist on using gcc. If
437+ someone tracks it down more completely I'd like to hear about it!
438+
439+ 3.8. Q. Other trouble building Python on platform X.
413440
414441A. Please email the details to <
[email protected] > and I'll look into it.
415442
@@ -761,6 +788,93 @@ This is not solely due to the lack of begin/end brackets (the lack of
761788declarations also helps, and the powerful operations of course), but
762789it certainly helps!
763790
791+ 6.5. Q. Why are Python strings immutable?
792+
793+ A. There are two advantages. One is performance: knowing that a
794+ string is immutable makes it easy to lay it out at construction time
795+ -- fixed and unchanging storage requirements. (This is also one of
796+ the reasons for the the distinction between tuples and lists.) The
797+ other is that strings in Python are considered as "elemental" as
798+ numbers. No amount of activity will change the value 8 to anything
799+ else, and in Python, no amount of activity will change the string
800+ "eight" to anything else. (Adapted from Jim Roskind)
801+
802+ 6.6. Q. Why don't strings have methods like index() or sort(), like
803+ lists?
804+
805+ A. Good question. Strings currently don't have methods at all
806+ (likewise tuples and numbers). Long ago, it seemed unnecessary to
807+ implement any of these functions in C, so a standard library module
808+ "string" written in Python was created that performs string related
809+ operations. Since then, the cry for performance has moved most of
810+ them into the built-in module strop (this is imported by module
811+ string, which is still the perferred interface, without loss of
812+ performance except during initialization). Some of these functions
813+ (e.g. index()) could easily be implemented as string methods instead,
814+ but others (e.g. sort()) can't, since their interface prescribes that
815+ they modify the object, while strings are immutable (see the previous
816+ question).
817+
818+ 6.7. Q. Why does Python use methods for some functionality
819+ (e.g. list.index()) but functions for other (e.g. len(list))?
820+
821+ A. Functions are used for those operations that are generic for a
822+ group of types and which should work even for objects that don't have
823+ methods at all (e.g. numbers, strings, tuples). Also, implementing
824+ len(), max(), min() as a built-in function is actually less code than
825+ implementing them as methods for each type. One can quibble about
826+ individual cases but it's really too late to change such things
827+ fundamentally now.
828+
829+ 6.8. Q. Why can't I derive a class from built-in types (e.g. lists or
830+ files)?
831+
832+ A. This is caused by the relatively late addition of (user-defined)
833+ classes to the language -- the implementation framework doesn't easily
834+ allow it. See the answer to question 4.2 for a work-around. This
835+ *may* be fixed in the (distant) future.
836+
837+ 6.9. Q. Why must 'self' be declared and used explicitly in method
838+ definitions and calls?
839+
840+ A. By asking this question you reveal your C++ background. :-)
841+ When I added classes, this was (again) the simplest way of
842+ implementing methods without too many changes to the interpreter. I
843+ borrowed the idea from Modula-3. It turns out to be very useful, for
844+ a variety of reasons.
845+
846+ First, it makes it more obvious that you are using a method or
847+ instance attribute instead of a local variable. Reading "self.x" or
848+ "self.meth()" makes it absolutely clear that an instance variable or
849+ method is used even if you don't know the class definition by heart.
850+ In C++, you can sort of tell by the lack of a local variable
851+ declaration (assuming globals are rare or reasily recognizable) -- but
852+ in Python, there are no local variable declarations, so you'd have to
853+ look up the class definition to be sure.
854+
855+ Second, it means that no special syntax is necessary if you want to
856+ explicitly reference or call the method from a particular class. In
857+ C++, if you want to use a method from base class that is overridden in
858+ a derived class, you have to use the :: operator -- in Python you can
859+ write baseclass.methodname(self, <argument list>). This is
860+ particularly useful for __init__() methods, and in general in cases
861+ where a derived class method wants to extend the base class method of
862+ the same name and thus has to call the base class method somehow.
863+
864+ Lastly, for instance variables, it solves a syntactic problem with
865+ assignment: since local variables in Python are (by definition!) those
866+ variables to which a value assigned in a function body (and that
867+ aren't explicitly declared global), there has to be some way to tell
868+ the interpreter that an assignment was meant to assign to an instance
869+ variable instead of to a local variable, and it should preferably be
870+ syntactic (for efficiency reasons). C++ does this through
871+ declarations, but Python doesn't have declarations and it would be a
872+ pity having to introduce them just for this purpose. Using the
873+ explicit "self.var" solves this nicely. Similarly, for using instance
874+ variables, having to write "self.var" means that references to
875+ unqualified names inside a method don't have to search the instance's
876+ directories.
877+
764878
7658797. Using Python on non-UNIX platforms
766880=====================================
@@ -805,9 +919,9 @@ Where's the library?
805919
806920A. You still need to copy the files from the distribution directory
807921"python/Lib" to your system. If you don't have the full distribution,
808- you can get the file pythonlib1.0.2. tar.gz from most ftp sites carrying
809- Python; this is a subset of the distribution containing just those
810- file.
922+ you can get the file pythonlib<version>. tar.gz from most ftp sites
923+ carrying Python; this is a subset of the distribution containing just
924+ those file.
811925
812926Once you have installed the library, you need to point sys.path to it.
813927Assuming the library is in C:\misc\python\lib, the following commands
0 commit comments