blob: 3f7152967484a6afaf509a0b99a4496cec681299 [file] [log] [blame]
Georg Brandld7413152009-10-11 21:25:26 +00001:tocdepth: 2
2
3==================
4General Python FAQ
5==================
6
Georg Brandl44ea77b2013-03-28 13:28:44 +01007.. only:: html
8
9 .. contents::
10
Georg Brandld7413152009-10-11 21:25:26 +000011
12General Information
13===================
14
15What is Python?
16---------------
17
18Python is an interpreted, interactive, object-oriented programming language. It
19incorporates modules, exceptions, dynamic typing, very high level dynamic data
20types, and classes. Python combines remarkable power with very clear syntax.
21It has interfaces to many system calls and libraries, as well as to various
22window systems, and is extensible in C or C++. It is also usable as an
23extension language for applications that need a programmable interface.
24Finally, Python is portable: it runs on many Unix variants, on the Mac, and on
Antoine Pitroucc809a22011-12-03 22:39:13 +010025Windows 2000 and later.
Georg Brandld7413152009-10-11 21:25:26 +000026
27To find out more, start with :ref:`tutorial-index`. The `Beginner's Guide to
Georg Brandle73778c2014-10-29 08:36:35 +010028Python <https://wiki.python.org/moin/BeginnersGuide>`_ links to other
Georg Brandld7413152009-10-11 21:25:26 +000029introductory tutorials and resources for learning Python.
30
31
32What is the Python Software Foundation?
33---------------------------------------
34
35The Python Software Foundation is an independent non-profit organization that
36holds the copyright on Python versions 2.1 and newer. The PSF's mission is to
37advance open source technology related to the Python programming language and to
38publicize the use of Python. The PSF's home page is at
Georg Brandle73778c2014-10-29 08:36:35 +010039https://www.python.org/psf/.
Georg Brandld7413152009-10-11 21:25:26 +000040
41Donations to the PSF are tax-exempt in the US. If you use Python and find it
42helpful, please contribute via `the PSF donation page
Georg Brandle73778c2014-10-29 08:36:35 +010043<https://www.python.org/psf/donations/>`_.
Georg Brandld7413152009-10-11 21:25:26 +000044
45
46Are there copyright restrictions on the use of Python?
47------------------------------------------------------
48
49You can do anything you want with the source, as long as you leave the
50copyrights in and display those copyrights in any documentation about Python
51that you produce. If you honor the copyright rules, it's OK to use Python for
52commercial use, to sell copies of Python in source or binary form (modified or
53unmodified), or to sell products that incorporate Python in some form. We would
54still like to know about all commercial use of Python, of course.
55
Ned Deily72c24002015-05-27 15:37:00 -070056See `the PSF license page <https://www.python.org/psf/license/>`_ to find further
Georg Brandld7413152009-10-11 21:25:26 +000057explanations and a link to the full text of the license.
58
59The Python logo is trademarked, and in certain cases permission is required to
60use it. Consult `the Trademark Usage Policy
Georg Brandle73778c2014-10-29 08:36:35 +010061<https://www.python.org/psf/trademarks/>`__ for more information.
Georg Brandld7413152009-10-11 21:25:26 +000062
63
64Why was Python created in the first place?
65------------------------------------------
66
67Here's a *very* brief summary of what started it all, written by Guido van
68Rossum:
69
70 I had extensive experience with implementing an interpreted language in the
71 ABC group at CWI, and from working with this group I had learned a lot about
72 language design. This is the origin of many Python features, including the
73 use of indentation for statement grouping and the inclusion of
74 very-high-level data types (although the details are all different in
75 Python).
76
77 I had a number of gripes about the ABC language, but also liked many of its
78 features. It was impossible to extend the ABC language (or its
79 implementation) to remedy my complaints -- in fact its lack of extensibility
80 was one of its biggest problems. I had some experience with using Modula-2+
81 and talked with the designers of Modula-3 and read the Modula-3 report.
82 Modula-3 is the origin of the syntax and semantics used for exceptions, and
83 some other Python features.
84
85 I was working in the Amoeba distributed operating system group at CWI. We
86 needed a better way to do system administration than by writing either C
87 programs or Bourne shell scripts, since Amoeba had its own system call
88 interface which wasn't easily accessible from the Bourne shell. My
89 experience with error handling in Amoeba made me acutely aware of the
90 importance of exceptions as a programming language feature.
91
92 It occurred to me that a scripting language with a syntax like ABC but with
93 access to the Amoeba system calls would fill the need. I realized that it
94 would be foolish to write an Amoeba-specific language, so I decided that I
95 needed a language that was generally extensible.
96
97 During the 1989 Christmas holidays, I had a lot of time on my hand, so I
98 decided to give it a try. During the next year, while still mostly working
99 on it in my own time, Python was used in the Amoeba project with increasing
100 success, and the feedback from colleagues made me add many early
101 improvements.
102
103 In February 1991, after just over a year of development, I decided to post to
104 USENET. The rest is in the ``Misc/HISTORY`` file.
105
106
107What is Python good for?
108------------------------
109
110Python is a high-level general-purpose programming language that can be applied
111to many different classes of problems.
112
113The language comes with a large standard library that covers areas such as
114string processing (regular expressions, Unicode, calculating differences between
115files), Internet protocols (HTTP, FTP, SMTP, XML-RPC, POP, IMAP, CGI
116programming), software engineering (unit testing, logging, profiling, parsing
117Python code), and operating system interfaces (system calls, filesystems, TCP/IP
118sockets). Look at the table of contents for :ref:`library-index` to get an idea
119of what's available. A wide variety of third-party extensions are also
Georg Brandle73778c2014-10-29 08:36:35 +0100120available. Consult `the Python Package Index <https://pypi.python.org/pypi>`_ to
Georg Brandld7413152009-10-11 21:25:26 +0000121find packages of interest to you.
122
123
124How does the Python version numbering scheme work?
125--------------------------------------------------
126
127Python versions are numbered A.B.C or A.B. A is the major version number -- it
128is only incremented for really major changes in the language. B is the minor
129version number, incremented for less earth-shattering changes. C is the
130micro-level -- it is incremented for each bugfix release. See :pep:`6` for more
131information about bugfix releases.
132
133Not all releases are bugfix releases. In the run-up to a new major release, a
134series of development releases are made, denoted as alpha, beta, or release
135candidate. Alphas are early releases in which interfaces aren't yet finalized;
136it's not unexpected to see an interface change between two alpha releases.
137Betas are more stable, preserving existing interfaces but possibly adding new
138modules, and release candidates are frozen, making no changes except as needed
139to fix critical bugs.
140
141Alpha, beta and release candidate versions have an additional suffix. The
142suffix for an alpha version is "aN" for some small number N, the suffix for a
143beta version is "bN" for some small number N, and the suffix for a release
144candidate version is "cN" for some small number N. In other words, all versions
145labeled 2.0aN precede the versions labeled 2.0bN, which precede versions labeled
1462.0cN, and *those* precede 2.0.
147
148You may also find version numbers with a "+" suffix, e.g. "2.2+". These are
149unreleased versions, built directly from the Subversion trunk. In practice,
150after a final minor release is made, the Subversion trunk is incremented to the
151next minor version, which becomes the "a0" version,
152e.g. "2.4a0".
153
Benjamin Petersonb39518802015-10-11 23:03:22 -0700154See also the documentation for :data:`sys.version`, :data:`sys.hexversion`, and
155:data:`sys.version_info`.
Georg Brandld7413152009-10-11 21:25:26 +0000156
157
158How do I obtain a copy of the Python source?
159--------------------------------------------
160
161The latest Python source distribution is always available from python.org, at
Georg Brandl5d941342016-02-26 19:37:12 +0100162https://www.python.org/downloads/. The latest development sources can be obtained
Georg Brandle73778c2014-10-29 08:36:35 +0100163via anonymous Mercurial access at https://hg.python.org/cpython.
Georg Brandld7413152009-10-11 21:25:26 +0000164
165The source distribution is a gzipped tar file containing the complete C source,
166Sphinx-formatted documentation, Python library modules, example programs, and
167several useful pieces of freely distributable software. The source will compile
168and run out of the box on most UNIX platforms.
169
Ned Deily29020b12014-09-01 00:06:18 -0700170Consult the `Getting Started section of the Python Developer's Guide
171<https://docs.python.org/devguide/setup.html>`__ for more
Georg Brandl495f7b52009-10-27 15:28:25 +0000172information on getting the source code and compiling it.
Georg Brandld7413152009-10-11 21:25:26 +0000173
174
175How do I get documentation on Python?
176-------------------------------------
177
178.. XXX mention py3k
179
180The standard documentation for the current stable version of Python is available
Georg Brandlb7354a62014-10-29 10:57:37 +0100181at https://docs.python.org/3/. PDF, plain text, and downloadable HTML versions are
182also available at https://docs.python.org/3/download.html.
Georg Brandld7413152009-10-11 21:25:26 +0000183
184The documentation is written in reStructuredText and processed by `the Sphinx
Benjamin Peterson714d7ff2014-01-25 13:27:06 -0500185documentation tool <http://sphinx-doc.org/>`__. The reStructuredText source for
186the documentation is part of the Python source distribution.
Georg Brandld7413152009-10-11 21:25:26 +0000187
188
189I've never programmed before. Is there a Python tutorial?
190---------------------------------------------------------
191
192There are numerous tutorials and books available. The standard documentation
193includes :ref:`tutorial-index`.
194
Georg Brandle73778c2014-10-29 08:36:35 +0100195Consult `the Beginner's Guide <https://wiki.python.org/moin/BeginnersGuide>`_ to
Georg Brandld7413152009-10-11 21:25:26 +0000196find information for beginning Python programmers, including lists of tutorials.
197
198
199Is there a newsgroup or mailing list devoted to Python?
200-------------------------------------------------------
201
202There is a newsgroup, :newsgroup:`comp.lang.python`, and a mailing list,
Georg Brandlb7354a62014-10-29 10:57:37 +0100203`python-list <https://mail.python.org/mailman/listinfo/python-list>`_. The
Georg Brandld7413152009-10-11 21:25:26 +0000204newsgroup and mailing list are gatewayed into each other -- if you can read news
205it's unnecessary to subscribe to the mailing list.
206:newsgroup:`comp.lang.python` is high-traffic, receiving hundreds of postings
207every day, and Usenet readers are often more able to cope with this volume.
208
209Announcements of new software releases and events can be found in
210comp.lang.python.announce, a low-traffic moderated list that receives about five
211postings per day. It's available as `the python-announce mailing list
Georg Brandlb7354a62014-10-29 10:57:37 +0100212<https://mail.python.org/mailman/listinfo/python-announce-list>`_.
Georg Brandld7413152009-10-11 21:25:26 +0000213
214More info about other mailing lists and newsgroups
Georg Brandle73778c2014-10-29 08:36:35 +0100215can be found at https://www.python.org/community/lists/.
Georg Brandld7413152009-10-11 21:25:26 +0000216
217
218How do I get a beta test version of Python?
219-------------------------------------------
220
Georg Brandl5d941342016-02-26 19:37:12 +0100221Alpha and beta releases are available from https://www.python.org/downloads/. All
Georg Brandld7413152009-10-11 21:25:26 +0000222releases are announced on the comp.lang.python and comp.lang.python.announce
Georg Brandle73778c2014-10-29 08:36:35 +0100223newsgroups and on the Python home page at https://www.python.org/; an RSS feed of
Georg Brandld7413152009-10-11 21:25:26 +0000224news is available.
225
Georg Brandl77fe77d2014-10-29 09:24:54 +0100226You can also access the development version of Python through Mercurial. See
227https://docs.python.org/devguide/faq.html for details.
Georg Brandld7413152009-10-11 21:25:26 +0000228
229
230How do I submit bug reports and patches for Python?
231---------------------------------------------------
232
233To report a bug or submit a patch, please use the Roundup installation at
Georg Brandle73778c2014-10-29 08:36:35 +0100234https://bugs.python.org/.
Georg Brandld7413152009-10-11 21:25:26 +0000235
236You must have a Roundup account to report bugs; this makes it possible for us to
237contact you if we have follow-up questions. It will also enable Roundup to send
238you updates as we act on your bug. If you had previously used SourceForge to
239report bugs to Python, you can obtain your Roundup password through Roundup's
Georg Brandle73778c2014-10-29 08:36:35 +0100240`password reset procedure <https://bugs.python.org/user?@template=forgotten>`_.
Georg Brandld7413152009-10-11 21:25:26 +0000241
Georg Brandld7413152009-10-11 21:25:26 +0000242For more information on how Python is developed, consult `the Python Developer's
Georg Brandle73778c2014-10-29 08:36:35 +0100243Guide <https://docs.python.org/devguide/>`_.
Georg Brandld7413152009-10-11 21:25:26 +0000244
245
246Are there any published articles about Python that I can reference?
247-------------------------------------------------------------------
248
249It's probably best to cite your favorite book about Python.
250
251The very first article about Python was written in 1991 and is now quite
252outdated.
253
254 Guido van Rossum and Jelke de Boer, "Interactively Testing Remote Servers
255 Using the Python Programming Language", CWI Quarterly, Volume 4, Issue 4
256 (December 1991), Amsterdam, pp 283-303.
257
258
259Are there any books on Python?
260------------------------------
261
262Yes, there are many, and more are being published. See the python.org wiki at
Georg Brandle73778c2014-10-29 08:36:35 +0100263https://wiki.python.org/moin/PythonBooks for a list.
Georg Brandld7413152009-10-11 21:25:26 +0000264
265You can also search online bookstores for "Python" and filter out the Monty
266Python references; or perhaps search for "Python" and "language".
267
268
269Where in the world is www.python.org located?
270---------------------------------------------
271
Benjamin Petersonf580d5b2014-01-24 23:59:57 -0500272The Python project's infrastructure is located all over the world.
Georg Brandl485922e2014-10-29 08:52:43 +0100273`www.python.org <https://www.python.org>`_ is graciously hosted by `Rackspace
Serhiy Storchaka6dff0202016-05-07 10:49:07 +0300274<https://www.rackspace.com>`_, with CDN caching provided by `Fastly
Georg Brandl485922e2014-10-29 08:52:43 +0100275<https://www.fastly.com>`_. `Upfront Systems
Georg Brandl5d941342016-02-26 19:37:12 +0100276<http://www.upfrontsystems.co.za/>`_ hosts `bugs.python.org
Georg Brandl485922e2014-10-29 08:52:43 +0100277<https://bugs.python.org>`_. Many other Python services like `the Wiki
278<https://wiki.python.org>`_ are hosted by `Oregon State
Benjamin Petersonf580d5b2014-01-24 23:59:57 -0500279University Open Source Lab <https://osuosl.org>`_.
Georg Brandld7413152009-10-11 21:25:26 +0000280
281
282Why is it called Python?
283------------------------
284
285When he began implementing Python, Guido van Rossum was also reading the
286published scripts from `"Monty Python's Flying Circus"
Georg Brandl5d941342016-02-26 19:37:12 +0100287<https://en.wikipedia.org/wiki/Monty_Python>`__, a BBC comedy series from the 1970s. Van Rossum
Georg Brandld7413152009-10-11 21:25:26 +0000288thought he needed a name that was short, unique, and slightly mysterious, so he
289decided to call the language Python.
290
291
292Do I have to like "Monty Python's Flying Circus"?
293-------------------------------------------------
294
295No, but it helps. :)
296
297
298Python in the real world
299========================
300
301How stable is Python?
302---------------------
303
304Very stable. New, stable releases have been coming out roughly every 6 to 18
305months since 1991, and this seems likely to continue. Currently there are
306usually around 18 months between major releases.
307
308The developers issue "bugfix" releases of older versions, so the stability of
309existing releases gradually improves. Bugfix releases, indicated by a third
310component of the version number (e.g. 2.5.3, 2.6.2), are managed for stability;
311only fixes for known problems are included in a bugfix release, and it's
312guaranteed that interfaces will remain the same throughout a series of bugfix
313releases.
314
R. David Murray338eae32009-12-14 17:27:08 +0000315The latest stable releases can always be found on the `Python download page
Georg Brandl5d941342016-02-26 19:37:12 +0100316<https://www.python.org/downloads/>`_. There are two recommended production-ready
R. David Murray338eae32009-12-14 17:27:08 +0000317versions at this point in time, because at the moment there are two branches of
318stable releases: 2.x and 3.x. Python 3.x may be less useful than 2.x, since
319currently there is more third party software available for Python 2 than for
320Python 3. Python 2 code will generally not run unchanged in Python 3.
Georg Brandld7413152009-10-11 21:25:26 +0000321
322
323How many people are using Python?
324---------------------------------
325
326There are probably tens of thousands of users, though it's difficult to obtain
327an exact count.
328
329Python is available for free download, so there are no sales figures, and it's
330available from many different sites and packaged with many Linux distributions,
331so download statistics don't tell the whole story either.
332
333The comp.lang.python newsgroup is very active, but not all Python users post to
334the group or even read it.
335
336
337Have any significant projects been done in Python?
338--------------------------------------------------
339
Georg Brandl77fe77d2014-10-29 09:24:54 +0100340See https://www.python.org/about/success for a list of projects that use Python.
Georg Brandld7413152009-10-11 21:25:26 +0000341Consulting the proceedings for `past Python conferences
Georg Brandl77fe77d2014-10-29 09:24:54 +0100342<https://www.python.org/community/workshops/>`_ will reveal contributions from many
Georg Brandld7413152009-10-11 21:25:26 +0000343different companies and organizations.
344
345High-profile Python projects include `the Mailman mailing list manager
346<http://www.list.org>`_ and `the Zope application server
347<http://www.zope.org>`_. Several Linux distributions, most notably `Red Hat
Georg Brandl5d941342016-02-26 19:37:12 +0100348<https://www.redhat.com>`_, have written part or all of their installer and
Georg Brandld7413152009-10-11 21:25:26 +0000349system administration software in Python. Companies that use Python internally
350include Google, Yahoo, and Lucasfilm Ltd.
351
352
353What new developments are expected for Python in the future?
354------------------------------------------------------------
355
Georg Brandle73778c2014-10-29 08:36:35 +0100356See https://www.python.org/dev/peps/ for the Python Enhancement Proposals
Georg Brandld7413152009-10-11 21:25:26 +0000357(PEPs). PEPs are design documents describing a suggested new feature for Python,
358providing a concise technical specification and a rationale. Look for a PEP
359titled "Python X.Y Release Schedule", where X.Y is a version that hasn't been
360publicly released yet.
361
362New development is discussed on `the python-dev mailing list
Georg Brandle73778c2014-10-29 08:36:35 +0100363<https://mail.python.org/mailman/listinfo/python-dev/>`_.
Georg Brandld7413152009-10-11 21:25:26 +0000364
365
366Is it reasonable to propose incompatible changes to Python?
367-----------------------------------------------------------
368
369In general, no. There are already millions of lines of Python code around the
370world, so any change in the language that invalidates more than a very small
371fraction of existing programs has to be frowned upon. Even if you can provide a
372conversion program, there's still the problem of updating all documentation;
373many books have been written about Python, and we don't want to invalidate them
374all at a single stroke.
375
376Providing a gradual upgrade path is necessary if a feature has to be changed.
377:pep:`5` describes the procedure followed for introducing backward-incompatible
378changes while minimizing disruption for users.
379
380
Georg Brandld7413152009-10-11 21:25:26 +0000381Is Python a good language for beginning programmers?
382----------------------------------------------------
383
384Yes.
385
386It is still common to start students with a procedural and statically typed
387language such as Pascal, C, or a subset of C++ or Java. Students may be better
388served by learning Python as their first language. Python has a very simple and
389consistent syntax and a large standard library and, most importantly, using
390Python in a beginning programming course lets students concentrate on important
391programming skills such as problem decomposition and data type design. With
392Python, students can be quickly introduced to basic concepts such as loops and
393procedures. They can probably even work with user-defined objects in their very
394first course.
395
396For a student who has never programmed before, using a statically typed language
397seems unnatural. It presents additional complexity that the student must master
398and slows the pace of the course. The students are trying to learn to think
399like a computer, decompose problems, design consistent interfaces, and
400encapsulate data. While learning to use a statically typed language is
401important in the long term, it is not necessarily the best topic to address in
402the students' first programming course.
403
404Many other aspects of Python make it a good first language. Like Java, Python
405has a large standard library so that students can be assigned programming
406projects very early in the course that *do* something. Assignments aren't
407restricted to the standard four-function calculator and check balancing
408programs. By using the standard library, students can gain the satisfaction of
409working on realistic applications as they learn the fundamentals of programming.
410Using the standard library also teaches students about code reuse. Third-party
411modules such as PyGame are also helpful in extending the students' reach.
412
413Python's interactive interpreter enables students to test language features
414while they're programming. They can keep a window with the interpreter running
415while they enter their program's source in another window. If they can't
416remember the methods for a list, they can do something like this::
417
418 >>> L = []
Georg Brandl9205e9e2014-10-06 17:51:09 +0200419 >>> dir(L) # doctest: +NORMALIZE_WHITESPACE
420 ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
421 '__dir__', '__doc__', '__eq__', '__format__', '__ge__',
422 '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__',
423 '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__',
424 '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
425 '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__',
426 '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear',
427 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove',
Georg Brandld7413152009-10-11 21:25:26 +0000428 'reverse', 'sort']
Georg Brandl9205e9e2014-10-06 17:51:09 +0200429 >>> [d for d in dir(L) if '__' not in d]
430 ['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
431
Georg Brandld7413152009-10-11 21:25:26 +0000432 >>> help(L.append)
433 Help on built-in function append:
Georg Brandl9205e9e2014-10-06 17:51:09 +0200434 <BLANKLINE>
Georg Brandld7413152009-10-11 21:25:26 +0000435 append(...)
Georg Brandl9205e9e2014-10-06 17:51:09 +0200436 L.append(object) -> None -- append object to end
437 <BLANKLINE>
Georg Brandld7413152009-10-11 21:25:26 +0000438 >>> L.append(1)
439 >>> L
440 [1]
441
442With the interpreter, documentation is never far from the student as he's
443programming.
444
445There are also good IDEs for Python. IDLE is a cross-platform IDE for Python
446that is written in Python using Tkinter. PythonWin is a Windows-specific IDE.
447Emacs users will be happy to know that there is a very good Python mode for
448Emacs. All of these programming environments provide syntax highlighting,
449auto-indenting, and access to the interactive interpreter while coding. Consult
Larry Hastings3732ed22014-03-15 21:13:56 -0700450`the Python wiki <https://wiki.python.org/moin/PythonEditors>`_ for a full list
451of Python editing environments.
Georg Brandld7413152009-10-11 21:25:26 +0000452
453If you want to discuss Python's use in education, you may be interested in
454joining `the edu-sig mailing list
Georg Brandle73778c2014-10-29 08:36:35 +0100455<https://www.python.org/community/sigs/current/edu-sig>`_.