By Alex Martelli
Price: $39.99 USD
£28.50 GBP
Cover | Table of Contents
CLASSPATH. With most releases of Sun's Java
Development Kit (JDK), for example, you can run:C:\Jy>java -cp . jython-22
C:\Jy>java -cp . jython-22 -o C:\Jython-2.2 demo lib source
PATH or copy these command files
into any directory on your PATH
environment variable. Alternatively, as with any other program, you
can give a complete pathname to it at a command (shell) prompt, or in
the shell script (or .BAT file, shortcut target,
etc.) that runs it. On Windows, you can also use Start → Programs → Python
2.4 → Python (command line).PATH, other
environment variables affect the python
program. Some environment variables have the same effects as options
passed to python on the command line, as
documented in the next section. A few environment variables provide
settings not available via command-line options:PYTHONHOMEPYTHONPATHPATH
environment variable. Alternatively, as with any other program, you
can give a complete pathname to it at a command (shell) prompt, or in
the shell script (or .BAT file, shortcut target,
etc.) that runs it. On Windows, you can also use Start → Programs → Python
2.4 → Python (command line).PATH, other
environment variables affect the python
program. Some environment variables have the same effects as options
passed to python on the command line, as
documented in the next section. A few environment variables provide
settings not available via command-line options:PYTHONHOMEPYTHONPATHsys.path
variable. Modules, importing, and the sys.path variable are covered in
Chapter 7.PYTHONSTARTUPPYTHONSTARTUP file is not used when
you run a Python script; it is used only when you start an
interactive session.[path]jython {options} [ -j jar | -c command | file | - ] {arguments}
python.path, for example, is the Jython
equivalent of Python's environment variable PYTHONPATH. You can also set properties with
jython command-line options in the form
-D name = value.[path]IronPythonConsole {options} [-c command | file | - ] {arguments}
#) that is not inside a
string literal begins a comment. All characters after the # and up to the physical line end are part
of the comment, and the Python interpreter ignores them. A line
containing only whitespace, possibly with a comment, is known as a
blank line, and Python totally ignores it. In
an interactive interpreter session, you must enter an empty physical
line (without any whitespace or comment) to terminate a multiline
statement.#) that is not inside a
string literal begins a comment. All characters after the # and up to the physical line end are part
of the comment, and the Python interpreter ignores them. A line
containing only whitespace, possibly with a comment, is known as a
blank line, and Python totally ignores it. In
an interactive interpreter session, you must enter an empty physical
line (without any whitespace or comment) to terminate a multiline
statement.;). When a statement is too long to fit on
a single physical line, you can join two adjacent physical lines
into a logical line by ensuring that the first physical line has no
comment and ends with a backslash (\). However, Python automatically joins
adjacent physical lines into one logical line if an open parenthesis
((), bracket ([), or brace ({) has not yet been closed, and taking
advantage of this mechanism, generally produces more readable code
instead of explicitly inserting backslashes at physical line ends.
Triple-quoted string literals can also span physical lines. Physical
lines after the first one in a logical line are known as
type(
obj )
accepts any object as its argument and returns the type object that is
the type of obj. Built-in function isinstance( obj
, type
) returns True if object
obj has type
type (or any subclass thereof); otherwise,
it returns False.+ or -, if present, is a separate operator, as
discussed in "Arithmetic
Operations" on page 52.del statement
unbinds references.Operator | Description | Associativity |
|---|---|---|
' expr
,...' | String conversion | NA |
{ key
:
expr ,...} | Dictionary creation | NA |
[ expr
,...] | List creation | NA |
( expr
,...) | Tuple creation or just
parentheses | NA |
f
(
expr ,...) | Function call | L |
x
[
index : index
] | Slicing | L |
x
[
index ] | Indexing | L |
x.attr
| Attribute reference | L |
x
**
y | Exponentiation
(x to
yth power) | R |
~ x
| Bitwise NOT | NA |
+ x,
-
x | Unary plus and minus | NA |
x
* y,
x /
y, x // y, x
%
y | Multiplication, division, truncating
division, remainder | L |
x
+ y,
x -
y | Addition, subtraction | L |
x
<< y,
x >>
y | Left-shift,
right-shift | L |
x
&
y | Bitwise AND | L |
x
^
y | Bitwise XOR | L |
x
|
y | Bitwise OR | L |
x
< y,
x <=
y, x > y, x
>= y,
x <>
y, x != y, x
==
y | Comparisons (less than, less than or
equal, greater than, greater than or equal, inequality,
equality) |
z as read-only attributes z.real and z.imag. Trying to rebind these attributes on
a complex object raises an exception.+ or
- sign, and the + that joins a floating-point literal to an
imaginary one to make a complex number, are not part of the literals'
syntax. They are ordinary operators, subject to normal operator
precedence rules (see Table
4-2). For example, -2**2
evaluates to -4: exponentiation has
higher precedence than unary minus, so the whole expression parses as
-(2**2), not as (-2)**2.int, long, float, and complex. int and long drop their argument's fractional
part, if any (e.g., int(9.8) is
9). You can also call complex with two numeric arguments, giving
real and imaginary parts. You cannot convert a complex to another numeric type in this
way, because there is no single unambiguous way to convert a complex
number into, e.g., a float.len function takes any container as an
argument and returns the number of items in the container. The
built-in min and max functions take one argument, a
nonempty iterable whose items are comparable, and return the
smallest and largest items, respectively. You can also call min and max with multiple arguments, in which case
they return the smallest and largest arguments, respectively. The
built-in sum function takes one
argument, an iterable whose items are numbers, and returns the sum
of the numbers.