mirror of
https://github.com/python/cpython.git
synced 2024-11-29 12:54:02 +08:00
New blurb, derived from my Handbook of Object Technology abstract.
This commit is contained in:
parent
4552f3d6de
commit
f5831ae92e
70
Misc/BLURB
70
Misc/BLURB
@ -1,45 +1,29 @@
|
||||
What is Python?
|
||||
---------------
|
||||
What is Python? Executive Summary
|
||||
----------------------------------
|
||||
|
||||
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.
|
||||
Python is an interpreted, object-oriented, high-level programming
|
||||
language with dynamic semantics. Its high-level built in data
|
||||
structures, combined with dynamic typing and dynamic binding, make it
|
||||
very attractive for Rapid Application Development, as well as for use
|
||||
as a scripting or glue language to connect existing components
|
||||
together. Python's simple, easy to learn syntax emphasizes
|
||||
readability and therefore reduces the cost of program maintenance.
|
||||
Python supports modules and packages, which encourages program
|
||||
modularity and code reuse. The Python interpreter and the extensive
|
||||
standard library are available in source or binary form without charge
|
||||
for all major platforms, and can be freely distributed.
|
||||
|
||||
As a short example of what Python looks like, here's a script to
|
||||
print prime numbers (not blazingly fast, but readable!). When this
|
||||
file is made executable, it is callable directly from the UNIX shell
|
||||
(if your system supports #! in scripts and the python interpreter is
|
||||
installed at the indicated place).
|
||||
|
||||
#!/usr/local/bin/python
|
||||
|
||||
# Print prime numbers in a given range
|
||||
|
||||
def main():
|
||||
import sys
|
||||
min, max = 2, 0x7fffffff
|
||||
if sys.argv[1:]:
|
||||
min = int(eval(sys.argv[1]))
|
||||
if sys.argv[2:]:
|
||||
max = int(eval(sys.argv[2]))
|
||||
primes(min, max)
|
||||
|
||||
def primes(min, max):
|
||||
if 2 >= min: print 2
|
||||
primes = [2]
|
||||
i = 3
|
||||
while i <= max:
|
||||
for p in primes:
|
||||
if i%p == 0 or p*p > i: break
|
||||
if i%p <> 0:
|
||||
primes.append(i)
|
||||
if i >= min: print i
|
||||
i = i+2
|
||||
|
||||
main()
|
||||
Often, programmers fall in love with Python because of the increased
|
||||
productivity it provides. Since there is no compilation step, the
|
||||
edit-test-debug cycle is incredibly fast. Debugging Python programs is
|
||||
easy: a bug or bad input will never cause a segmentation
|
||||
fault. Instead, when the interpreter discovers an error, it raises an
|
||||
exception. When the program doesn't catch the exception, the
|
||||
interpreter prints a stack trace. A source level debugger allows
|
||||
inspection of local and global variables, evaluation of arbitrary
|
||||
expressions, setting breakpoints, stepping through the code a line at
|
||||
a time, and so on. The debugger is written in Python itself,
|
||||
testifying to Python's introspective power. On the other hand, often
|
||||
the quickest way to debug a program is to add a few print statements
|
||||
to the source: the fast edit-test-debug cycle makes this simple
|
||||
approach very effective.
|
||||
|
Loading…
Reference in New Issue
Block a user