Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2ea7f2ed
Commit
2ea7f2ed
authored
Apr 03, 1998
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Several minor markup nits.
parent
4c85328c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
64 deletions
+74
-64
Doc/lib/libtypes.tex
Doc/lib/libtypes.tex
+37
-32
Doc/libtypes.tex
Doc/libtypes.tex
+37
-32
No files found.
Doc/lib/libtypes.tex
View file @
2ea7f2ed
...
@@ -145,8 +145,8 @@ Again, such objects are ordered arbitrarily but consistently.
...
@@ -145,8 +145,8 @@ Again, such objects are ordered arbitrarily but consistently.
ordered by their type names; objects of the same types that don't
ordered by their type names; objects of the same types that don't
support proper comparison are ordered by their address.)
support proper comparison are ordered by their address.)
Two more operations with the same syntactic priority,
\
code
{
in
}
and
Two more operations with the same syntactic priority,
\
samp
{
in
}
and
\
code
{
not in
}
, are supported only by sequence types (below).
\
samp
{
not in
}
, are supported only by sequence types (below).
\opindex
{
in
}
\opindex
{
in
}
\opindex
{
not in
}
\opindex
{
not in
}
...
@@ -172,7 +172,7 @@ working with.
...
@@ -172,7 +172,7 @@ working with.
Complex numbers have a real and imaginary part, which are both
Complex numbers have a real and imaginary part, which are both
implemented using
\code
{
double
}
in
\C
{}
. To extract these parts from
implemented using
\code
{
double
}
in
\C
{}
. To extract these parts from
a complex number
\
code
{
z
}
, use
\code
{
z.real
}
and
\code
{
z
.imag
}
.
a complex number
\
var
{
z
}
, use
\code
{
\var
{
z
}
.real
}
and
\code
{
\var
{
z
}
.imag
}
.
Numbers are created by numeric literals or as the result of built-in
Numbers are created by numeric literals or as the result of built-in
functions and operators. Unadorned integer literals (including hex
functions and operators. Unadorned integer literals (including hex
...
@@ -230,7 +230,7 @@ comparison operations):
...
@@ -230,7 +230,7 @@ comparison operations):
\lineiii
{
complex(
\var
{
re
}
,
\var
{
im
}
)
}{
a complex number with real part
\var
{
re
}
, imaginary part
\var
{
im
}
.
\var
{
im
}
defaults to zero.
}{}
\lineiii
{
complex(
\var
{
re
}
,
\var
{
im
}
)
}{
a complex number with real part
\var
{
re
}
, imaginary part
\var
{
im
}
.
\var
{
im
}
defaults to zero.
}{}
\lineiii
{
divmod(
\var
{
x
}
,
\var
{
y
}
)
}{
the pair
\code
{
(
\var
{
x
}
/
\var
{
y
}
,
\var
{
x
}
\%
{}
\var
{
y
}
)
}}{
(3)
}
\lineiii
{
divmod(
\var
{
x
}
,
\var
{
y
}
)
}{
the pair
\code
{
(
\var
{
x
}
/
\var
{
y
}
,
\var
{
x
}
\%
{}
\var
{
y
}
)
}}{
(3)
}
\lineiii
{
pow(
\var
{
x
}
,
\var
{
y
}
)
}{
\var
{
x
}
to the power
\var
{
y
}}{}
\lineiii
{
pow(
\var
{
x
}
,
\var
{
y
}
)
}{
\var
{
x
}
to the power
\var
{
y
}}{}
\lineiii
{
\var
{
x
}
**
\var
{
y
}}{
\var
{
x
}
to the power
\var
{
y
}}{}
\lineiii
{
\var
{
x
}
**
\var
{
y
}}{
\var
{
x
}
to the power
\var
{
y
}}{}
\end{tableiii}
\end{tableiii}
\indexiii
{
operations on
}{
numeric
}{
types
}
\indexiii
{
operations on
}{
numeric
}{
types
}
...
@@ -400,10 +400,12 @@ required by the format string; if the string requires a single
...
@@ -400,10 +400,12 @@ required by the format string; if the string requires a single
argument, the right argument may also be a single non-tuple object.
%
argument, the right argument may also be a single non-tuple object.
%
\footnote
{
A tuple object in this case should be a singleton.
}
\footnote
{
A tuple object in this case should be a singleton.
}
The following format characters are understood:
The following format characters are understood:
\%
, c, s, i, d, u, o, x, X, e, E, f, g, G.
\code
{
\%
}
,
\code
{
c
}
,
\code
{
s
}
,
\code
{
i
}
,
\code
{
d
}
,
\code
{
u
}
,
\code
{
o
}
,
Width and precision may be a * to specify that an integer argument
\code
{
x
}
,
\code
{
X
}
,
\code
{
e
}
,
\code
{
E
}
,
\code
{
f
}
,
\code
{
g
}
,
\code
{
G
}
.
specifies the actual width or precision. The flag characters -, +,
Width and precision may be a
\code
{
*
}
to specify that an integer argument
blank,
\#
and 0 are understood. The size specifiers h, l or L may be
specifies the actual width or precision. The flag characters
\code
{
-
}
,
\code
{
+
}
, blank,
\code
{
\#
}
and
\code
{
0
}
are understood. The
size specifiers
\code
{
h
}
,
\code
{
l
}
or
\code
{
L
}
may be
present but are ignored. The
\code
{
\%
s
}
conversion takes any Python
present but are ignored. The
\code
{
\%
s
}
conversion takes any Python
object and converts it to a string using
\code
{
str()
}
before
object and converts it to a string using
\code
{
str()
}
before
formatting it. The ANSI features
\code
{
\%
p
}
and
\code
{
\%
n
}
formatting it. The ANSI features
\code
{
\%
p
}
and
\code
{
\%
n
}
...
@@ -431,10 +433,9 @@ For example:
...
@@ -431,10 +433,9 @@ For example:
>>> language = 'Python'
>>> language = 'Python'
>>> print '
%(language)s has %(count)03d quote types.' % vars()
>>> print '
%(language)s has %(count)03d quote types.' % vars()
Python has 002 quote types.
Python has 002 quote types.
>>>
\end{verbatim}
\end{verbatim}
In this case no
*
specifiers may occur in a format (since they
In this case no
\code
{
*
}
specifiers may occur in a format (since they
require a sequential parameter list).
require a sequential parameter list).
Additional string operations are defined in standard module
Additional string operations are defined in standard module
...
@@ -553,7 +554,7 @@ mapping, \var{k} is a key and \var{x} is an arbitrary object):
...
@@ -553,7 +554,7 @@ mapping, \var{k} is a key and \var{x} is an arbitrary object):
\lineiii
{
\var
{
a
}
.keys()
}{
a copy of
\var
{
a
}
's list of keys
}{
(2)
}
\lineiii
{
\var
{
a
}
.keys()
}{
a copy of
\var
{
a
}
's list of keys
}{
(2)
}
\lineiii
{
\var
{
a
}
.update(
\var
{
b
}
)
}{
\code
{
for k, v in
\var
{
b
}
.items():
\var
{
a
}
[k] = v
}}{
(3)
}
\lineiii
{
\var
{
a
}
.update(
\var
{
b
}
)
}{
\code
{
for k, v in
\var
{
b
}
.items():
\var
{
a
}
[k] = v
}}{
(3)
}
\lineiii
{
\var
{
a
}
.values()
}{
a copy of
\var
{
a
}
's list of values
}{
(2)
}
\lineiii
{
\var
{
a
}
.values()
}{
a copy of
\var
{
a
}
's list of values
}{
(2)
}
\lineiii
{
\var
{
a
}
.get(
\var
{
k
}
,
\var
{
f
}
)
}{
the item of
\var
{
a
}
with key
\var
{
k
}}{
(4)
}
\lineiii
{
\var
{
a
}
.get(
\var
{
k
}
\optional
{
,
\var
{
f
}
}
)
}{
the item of
\var
{
a
}
with key
\var
{
k
}}{
(4)
}
\end{tableiii}
\end{tableiii}
\indexiii
{
operations on
}{
mapping
}{
types
}
\indexiii
{
operations on
}{
mapping
}{
types
}
\indexiii
{
operations on
}{
dictionary
}{
type
}
\indexiii
{
operations on
}{
dictionary
}{
type
}
...
@@ -587,20 +588,21 @@ Most of these support only one or two operations.
...
@@ -587,20 +588,21 @@ Most of these support only one or two operations.
\subsubsection
{
Modules
}
\subsubsection
{
Modules
}
The only special operation on a module is attribute access:
The only special operation on a module is attribute access:
\code
{
\var
{
m
}
.
\var
{
name
}}
, where
\var
{
m
}
is a module and
\var
{
name
}
accesses
\code
{
\var
{
m
}
.
\var
{
name
}}
, where
\var
{
m
}
is a module and
\var
{
name
}
a
name defined in
\var
{
m
}
's symbol table. Module attributes can be
a
ccesses a name defined in
\var
{
m
}
's symbol table. Module attributes
assigned to. (Note that the
\code
{
import
}
statement is not, strictly
can be assigned to. (Note that the
\code
{
import
}
statement is not,
s
poken, an operation on a module object;
\code
{
import
\var
{
foo
}}
does no
t
s
trictly spoking, an operation on a module object;
\code
{
impor
t
require a module object named
\var
{
foo
}
to exist, rather it requires
\var
{
foo
}}
does not require a module object named
\var
{
foo
}
to exist,
an (external)
\emph
{
definition
}
for a module named
\var
{
foo
}
rather it requires an (external)
\emph
{
definition
}
for a module named
somewhere.)
\var
{
foo
}
somewhere.)
A special member of every module is
\code
{__
dict
__}
.
A special member of every module is
\code
{__
dict
__}
.
This is the dictionary containing the module's symbol table.
This is the dictionary containing the module's symbol table.
Modifying this dictionary will actually change the module's symbol
Modifying this dictionary will actually change the module's symbol
table, but direct assignment to the
\code
{__
dict
__}
attribute is not
table, but direct assignment to the
\code
{__
dict
__}
attribute is not
possible (i.e., you can write
\code
{
\var
{
m
}
.
__
dict
__
['a'] = 1
}
, which
possible (i.e., you can write
\code
{
\var
{
m
}
.
__
dict
__
['a'] = 1
}
, which
defines
\code
{
\var
{
m
}
.a
}
to be
\code
{
1
}
, but you can't write
\code
{
\var
{
m
}
.
__
dict
__
=
\{\}
}
.
defines
\code
{
\var
{
m
}
.a
}
to be
\code
{
1
}
, but you can't write
\code
{
\var
{
m
}
.
__
dict
__
=
\{\}
}
.
Modules are written like this:
\code
{
<module 'sys'>
}
.
Modules are written like this:
\code
{
<module 'sys'>
}
.
...
@@ -621,10 +623,12 @@ the function), but the implementation is different, hence the
...
@@ -621,10 +623,12 @@ the function), but the implementation is different, hence the
different object types.
different object types.
The implementation adds two special read-only attributes:
The implementation adds two special read-only attributes:
\code
{
\var
{
f
}
.func
_
code
}
is a function's
\dfn
{
code object
}
(see below) and
\code
{
\var
{
f
}
.func
_
code
}
is a function's
\dfn
{
code
\code
{
\var
{
f
}
.func
_
globals
}
is the dictionary used as the function's
object
}
\obindex
{
code
}
(see below) and
\code
{
\var
{
f
}
.func
_
globals
}
is
global name space (this is the same as
\code
{
\var
{
m
}
.
__
dict
__}
where
the dictionary used as the function's global name space (this is the
\var
{
m
}
is the module in which the function
\var
{
f
}
was defined).
same as
\code
{
\var
{
m
}
.
__
dict
__}
where
\var
{
m
}
is the module in which
the function
\var
{
f
}
was defined).
\subsubsection
{
Methods
}
\subsubsection
{
Methods
}
\obindex
{
method
}
\obindex
{
method
}
...
@@ -752,13 +756,13 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
...
@@ -752,13 +756,13 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
non-negative, it is a maximum byte count (including the trailing
non-negative, it is a maximum byte count (including the trailing
newline) and an incomplete line may be returned.
newline) and an incomplete line may be returned.
An empty string is returned when
\EOF
{}
is hit
An empty string is returned when
\EOF
{}
is hit
immediately. Note: unlike
\code
{
stdio
}
's
\c
ode
{
fgets()
}
, the returned
immediately. Note: unlike
\code
{
stdio
}
's
\c
function
{
fgets()
}
, the returned
string contains null characters (
\code
{
'
\e
0'
}
) if they occurred in the
string contains null characters (
\code
{
'
\e
0'
}
) if they occurred in the
input.
input.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
readlines
}{
\optional
{
sizehint
}}
\begin{methoddesc}
[file]
{
readlines
}{
\optional
{
sizehint
}}
Read until
\EOF
{}
using
\
code
{
readline()
}
and return a list containing
Read until
\EOF
{}
using
\
method
{
readline()
}
and return a list containing
the lines thus read. If the optional
\var
{
sizehint
}
argument is
the lines thus read. If the optional
\var
{
sizehint
}
argument is
present, instead of reading up to
\EOF
{}
, whole lines totalling
present, instead of reading up to
\EOF
{}
, whole lines totalling
approximately
\var
{
sizehint
}
bytes (possibly after rounding up to an
approximately
\var
{
sizehint
}
bytes (possibly after rounding up to an
...
@@ -766,7 +770,7 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
...
@@ -766,7 +770,7 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
seek
}{
offset, whence
}
\begin{methoddesc}
[file]
{
seek
}{
offset, whence
}
Set the file's current position, like
\code
{
stdio
}
's
\c
ode
{
fseek()
}
.
Set the file's current position, like
\code
{
stdio
}
's
\c
function
{
fseek()
}
.
The
\var
{
whence
}
argument is optional and defaults to
\code
{
0
}
The
\var
{
whence
}
argument is optional and defaults to
\code
{
0
}
(absolute file positioning); other values are
\code
{
1
}
(seek
(absolute file positioning); other values are
\code
{
1
}
(seek
relative to the current position) and
\code
{
2
}
(seek relative to the
relative to the current position) and
\code
{
2
}
(seek relative to the
...
@@ -774,7 +778,8 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
...
@@ -774,7 +778,8 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
tell
}{}
\begin{methoddesc}
[file]
{
tell
}{}
Return the file's current position, like
\code
{
stdio
}
's
\code
{
ftell()
}
.
Return the file's current position, like
\code
{
stdio
}
's
\cfunction
{
ftell()
}
.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
truncate
}{
\optional
{
size
}}
\begin{methoddesc}
[file]
{
truncate
}{
\optional
{
size
}}
...
@@ -788,13 +793,13 @@ operation).
...
@@ -788,13 +793,13 @@ operation).
\begin{methoddesc}
[file]
{
write
}{
str
}
\begin{methoddesc}
[file]
{
write
}{
str
}
Write a string to the file. There is no return value. Note: due to
Write a string to the file. There is no return value. Note: due to
buffering, the string may not actually show up in the file until
buffering, the string may not actually show up in the file until
the
\
code
{
flush()
}
or
\code
{
close()
}
method is called.
the
\
method
{
flush()
}
or
\method
{
close()
}
method is called.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
writelines
}{
list
}
\begin{methoddesc}
[file]
{
writelines
}{
list
}
Write a list of strings to the file. There is no return value.
Write a list of strings to the file. There is no return value.
(The name is intended to match
\
code
{
readlines
}
;
\code
{
writelines
}
(The name is intended to match
\
method
{
readlines()
}
;
does not add line separators.)
\method
{
writelines()
}
does not add line separators.)
\end{methoddesc}
\end{methoddesc}
File objects also offer the following attributes:
File objects also offer the following attributes:
...
@@ -823,9 +828,9 @@ attribute.
...
@@ -823,9 +828,9 @@ attribute.
Boolean that indicates whether a space character needs to be printed
Boolean that indicates whether a space character needs to be printed
before another value when using the
\keyword
{
print
}
statement.
before another value when using the
\keyword
{
print
}
statement.
Classes that are trying to simulate a file object should also have a
Classes that are trying to simulate a file object should also have a
writable
\
code
{
softspace
}
attribute, which should be initialized to
writable
\
member
{
softspace
}
attribute, which should be initialized to
zero. This will be automatic for classes implemented in Python; types
zero. This will be automatic for classes implemented in Python; types
implemented in
\C
{}
will have to provide a writable
\
code
{
softspace
}
implemented in
\C
{}
will have to provide a writable
\
member
{
softspace
}
attribute.
attribute.
\end{memberdesc}
\end{memberdesc}
...
...
Doc/libtypes.tex
View file @
2ea7f2ed
...
@@ -145,8 +145,8 @@ Again, such objects are ordered arbitrarily but consistently.
...
@@ -145,8 +145,8 @@ Again, such objects are ordered arbitrarily but consistently.
ordered by their type names; objects of the same types that don't
ordered by their type names; objects of the same types that don't
support proper comparison are ordered by their address.)
support proper comparison are ordered by their address.)
Two more operations with the same syntactic priority,
\
code
{
in
}
and
Two more operations with the same syntactic priority,
\
samp
{
in
}
and
\
code
{
not in
}
, are supported only by sequence types (below).
\
samp
{
not in
}
, are supported only by sequence types (below).
\opindex
{
in
}
\opindex
{
in
}
\opindex
{
not in
}
\opindex
{
not in
}
...
@@ -172,7 +172,7 @@ working with.
...
@@ -172,7 +172,7 @@ working with.
Complex numbers have a real and imaginary part, which are both
Complex numbers have a real and imaginary part, which are both
implemented using
\code
{
double
}
in
\C
{}
. To extract these parts from
implemented using
\code
{
double
}
in
\C
{}
. To extract these parts from
a complex number
\
code
{
z
}
, use
\code
{
z.real
}
and
\code
{
z
.imag
}
.
a complex number
\
var
{
z
}
, use
\code
{
\var
{
z
}
.real
}
and
\code
{
\var
{
z
}
.imag
}
.
Numbers are created by numeric literals or as the result of built-in
Numbers are created by numeric literals or as the result of built-in
functions and operators. Unadorned integer literals (including hex
functions and operators. Unadorned integer literals (including hex
...
@@ -230,7 +230,7 @@ comparison operations):
...
@@ -230,7 +230,7 @@ comparison operations):
\lineiii
{
complex(
\var
{
re
}
,
\var
{
im
}
)
}{
a complex number with real part
\var
{
re
}
, imaginary part
\var
{
im
}
.
\var
{
im
}
defaults to zero.
}{}
\lineiii
{
complex(
\var
{
re
}
,
\var
{
im
}
)
}{
a complex number with real part
\var
{
re
}
, imaginary part
\var
{
im
}
.
\var
{
im
}
defaults to zero.
}{}
\lineiii
{
divmod(
\var
{
x
}
,
\var
{
y
}
)
}{
the pair
\code
{
(
\var
{
x
}
/
\var
{
y
}
,
\var
{
x
}
\%
{}
\var
{
y
}
)
}}{
(3)
}
\lineiii
{
divmod(
\var
{
x
}
,
\var
{
y
}
)
}{
the pair
\code
{
(
\var
{
x
}
/
\var
{
y
}
,
\var
{
x
}
\%
{}
\var
{
y
}
)
}}{
(3)
}
\lineiii
{
pow(
\var
{
x
}
,
\var
{
y
}
)
}{
\var
{
x
}
to the power
\var
{
y
}}{}
\lineiii
{
pow(
\var
{
x
}
,
\var
{
y
}
)
}{
\var
{
x
}
to the power
\var
{
y
}}{}
\lineiii
{
\var
{
x
}
**
\var
{
y
}}{
\var
{
x
}
to the power
\var
{
y
}}{}
\lineiii
{
\var
{
x
}
**
\var
{
y
}}{
\var
{
x
}
to the power
\var
{
y
}}{}
\end{tableiii}
\end{tableiii}
\indexiii
{
operations on
}{
numeric
}{
types
}
\indexiii
{
operations on
}{
numeric
}{
types
}
...
@@ -400,10 +400,12 @@ required by the format string; if the string requires a single
...
@@ -400,10 +400,12 @@ required by the format string; if the string requires a single
argument, the right argument may also be a single non-tuple object.
%
argument, the right argument may also be a single non-tuple object.
%
\footnote
{
A tuple object in this case should be a singleton.
}
\footnote
{
A tuple object in this case should be a singleton.
}
The following format characters are understood:
The following format characters are understood:
\%
, c, s, i, d, u, o, x, X, e, E, f, g, G.
\code
{
\%
}
,
\code
{
c
}
,
\code
{
s
}
,
\code
{
i
}
,
\code
{
d
}
,
\code
{
u
}
,
\code
{
o
}
,
Width and precision may be a * to specify that an integer argument
\code
{
x
}
,
\code
{
X
}
,
\code
{
e
}
,
\code
{
E
}
,
\code
{
f
}
,
\code
{
g
}
,
\code
{
G
}
.
specifies the actual width or precision. The flag characters -, +,
Width and precision may be a
\code
{
*
}
to specify that an integer argument
blank,
\#
and 0 are understood. The size specifiers h, l or L may be
specifies the actual width or precision. The flag characters
\code
{
-
}
,
\code
{
+
}
, blank,
\code
{
\#
}
and
\code
{
0
}
are understood. The
size specifiers
\code
{
h
}
,
\code
{
l
}
or
\code
{
L
}
may be
present but are ignored. The
\code
{
\%
s
}
conversion takes any Python
present but are ignored. The
\code
{
\%
s
}
conversion takes any Python
object and converts it to a string using
\code
{
str()
}
before
object and converts it to a string using
\code
{
str()
}
before
formatting it. The ANSI features
\code
{
\%
p
}
and
\code
{
\%
n
}
formatting it. The ANSI features
\code
{
\%
p
}
and
\code
{
\%
n
}
...
@@ -431,10 +433,9 @@ For example:
...
@@ -431,10 +433,9 @@ For example:
>>> language = 'Python'
>>> language = 'Python'
>>> print '
%(language)s has %(count)03d quote types.' % vars()
>>> print '
%(language)s has %(count)03d quote types.' % vars()
Python has 002 quote types.
Python has 002 quote types.
>>>
\end{verbatim}
\end{verbatim}
In this case no
*
specifiers may occur in a format (since they
In this case no
\code
{
*
}
specifiers may occur in a format (since they
require a sequential parameter list).
require a sequential parameter list).
Additional string operations are defined in standard module
Additional string operations are defined in standard module
...
@@ -553,7 +554,7 @@ mapping, \var{k} is a key and \var{x} is an arbitrary object):
...
@@ -553,7 +554,7 @@ mapping, \var{k} is a key and \var{x} is an arbitrary object):
\lineiii
{
\var
{
a
}
.keys()
}{
a copy of
\var
{
a
}
's list of keys
}{
(2)
}
\lineiii
{
\var
{
a
}
.keys()
}{
a copy of
\var
{
a
}
's list of keys
}{
(2)
}
\lineiii
{
\var
{
a
}
.update(
\var
{
b
}
)
}{
\code
{
for k, v in
\var
{
b
}
.items():
\var
{
a
}
[k] = v
}}{
(3)
}
\lineiii
{
\var
{
a
}
.update(
\var
{
b
}
)
}{
\code
{
for k, v in
\var
{
b
}
.items():
\var
{
a
}
[k] = v
}}{
(3)
}
\lineiii
{
\var
{
a
}
.values()
}{
a copy of
\var
{
a
}
's list of values
}{
(2)
}
\lineiii
{
\var
{
a
}
.values()
}{
a copy of
\var
{
a
}
's list of values
}{
(2)
}
\lineiii
{
\var
{
a
}
.get(
\var
{
k
}
,
\var
{
f
}
)
}{
the item of
\var
{
a
}
with key
\var
{
k
}}{
(4)
}
\lineiii
{
\var
{
a
}
.get(
\var
{
k
}
\optional
{
,
\var
{
f
}
}
)
}{
the item of
\var
{
a
}
with key
\var
{
k
}}{
(4)
}
\end{tableiii}
\end{tableiii}
\indexiii
{
operations on
}{
mapping
}{
types
}
\indexiii
{
operations on
}{
mapping
}{
types
}
\indexiii
{
operations on
}{
dictionary
}{
type
}
\indexiii
{
operations on
}{
dictionary
}{
type
}
...
@@ -587,20 +588,21 @@ Most of these support only one or two operations.
...
@@ -587,20 +588,21 @@ Most of these support only one or two operations.
\subsubsection
{
Modules
}
\subsubsection
{
Modules
}
The only special operation on a module is attribute access:
The only special operation on a module is attribute access:
\code
{
\var
{
m
}
.
\var
{
name
}}
, where
\var
{
m
}
is a module and
\var
{
name
}
accesses
\code
{
\var
{
m
}
.
\var
{
name
}}
, where
\var
{
m
}
is a module and
\var
{
name
}
a
name defined in
\var
{
m
}
's symbol table. Module attributes can be
a
ccesses a name defined in
\var
{
m
}
's symbol table. Module attributes
assigned to. (Note that the
\code
{
import
}
statement is not, strictly
can be assigned to. (Note that the
\code
{
import
}
statement is not,
s
poken, an operation on a module object;
\code
{
import
\var
{
foo
}}
does no
t
s
trictly spoking, an operation on a module object;
\code
{
impor
t
require a module object named
\var
{
foo
}
to exist, rather it requires
\var
{
foo
}}
does not require a module object named
\var
{
foo
}
to exist,
an (external)
\emph
{
definition
}
for a module named
\var
{
foo
}
rather it requires an (external)
\emph
{
definition
}
for a module named
somewhere.)
\var
{
foo
}
somewhere.)
A special member of every module is
\code
{__
dict
__}
.
A special member of every module is
\code
{__
dict
__}
.
This is the dictionary containing the module's symbol table.
This is the dictionary containing the module's symbol table.
Modifying this dictionary will actually change the module's symbol
Modifying this dictionary will actually change the module's symbol
table, but direct assignment to the
\code
{__
dict
__}
attribute is not
table, but direct assignment to the
\code
{__
dict
__}
attribute is not
possible (i.e., you can write
\code
{
\var
{
m
}
.
__
dict
__
['a'] = 1
}
, which
possible (i.e., you can write
\code
{
\var
{
m
}
.
__
dict
__
['a'] = 1
}
, which
defines
\code
{
\var
{
m
}
.a
}
to be
\code
{
1
}
, but you can't write
\code
{
\var
{
m
}
.
__
dict
__
=
\{\}
}
.
defines
\code
{
\var
{
m
}
.a
}
to be
\code
{
1
}
, but you can't write
\code
{
\var
{
m
}
.
__
dict
__
=
\{\}
}
.
Modules are written like this:
\code
{
<module 'sys'>
}
.
Modules are written like this:
\code
{
<module 'sys'>
}
.
...
@@ -621,10 +623,12 @@ the function), but the implementation is different, hence the
...
@@ -621,10 +623,12 @@ the function), but the implementation is different, hence the
different object types.
different object types.
The implementation adds two special read-only attributes:
The implementation adds two special read-only attributes:
\code
{
\var
{
f
}
.func
_
code
}
is a function's
\dfn
{
code object
}
(see below) and
\code
{
\var
{
f
}
.func
_
code
}
is a function's
\dfn
{
code
\code
{
\var
{
f
}
.func
_
globals
}
is the dictionary used as the function's
object
}
\obindex
{
code
}
(see below) and
\code
{
\var
{
f
}
.func
_
globals
}
is
global name space (this is the same as
\code
{
\var
{
m
}
.
__
dict
__}
where
the dictionary used as the function's global name space (this is the
\var
{
m
}
is the module in which the function
\var
{
f
}
was defined).
same as
\code
{
\var
{
m
}
.
__
dict
__}
where
\var
{
m
}
is the module in which
the function
\var
{
f
}
was defined).
\subsubsection
{
Methods
}
\subsubsection
{
Methods
}
\obindex
{
method
}
\obindex
{
method
}
...
@@ -752,13 +756,13 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
...
@@ -752,13 +756,13 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
non-negative, it is a maximum byte count (including the trailing
non-negative, it is a maximum byte count (including the trailing
newline) and an incomplete line may be returned.
newline) and an incomplete line may be returned.
An empty string is returned when
\EOF
{}
is hit
An empty string is returned when
\EOF
{}
is hit
immediately. Note: unlike
\code
{
stdio
}
's
\c
ode
{
fgets()
}
, the returned
immediately. Note: unlike
\code
{
stdio
}
's
\c
function
{
fgets()
}
, the returned
string contains null characters (
\code
{
'
\e
0'
}
) if they occurred in the
string contains null characters (
\code
{
'
\e
0'
}
) if they occurred in the
input.
input.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
readlines
}{
\optional
{
sizehint
}}
\begin{methoddesc}
[file]
{
readlines
}{
\optional
{
sizehint
}}
Read until
\EOF
{}
using
\
code
{
readline()
}
and return a list containing
Read until
\EOF
{}
using
\
method
{
readline()
}
and return a list containing
the lines thus read. If the optional
\var
{
sizehint
}
argument is
the lines thus read. If the optional
\var
{
sizehint
}
argument is
present, instead of reading up to
\EOF
{}
, whole lines totalling
present, instead of reading up to
\EOF
{}
, whole lines totalling
approximately
\var
{
sizehint
}
bytes (possibly after rounding up to an
approximately
\var
{
sizehint
}
bytes (possibly after rounding up to an
...
@@ -766,7 +770,7 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
...
@@ -766,7 +770,7 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
seek
}{
offset, whence
}
\begin{methoddesc}
[file]
{
seek
}{
offset, whence
}
Set the file's current position, like
\code
{
stdio
}
's
\c
ode
{
fseek()
}
.
Set the file's current position, like
\code
{
stdio
}
's
\c
function
{
fseek()
}
.
The
\var
{
whence
}
argument is optional and defaults to
\code
{
0
}
The
\var
{
whence
}
argument is optional and defaults to
\code
{
0
}
(absolute file positioning); other values are
\code
{
1
}
(seek
(absolute file positioning); other values are
\code
{
1
}
(seek
relative to the current position) and
\code
{
2
}
(seek relative to the
relative to the current position) and
\code
{
2
}
(seek relative to the
...
@@ -774,7 +778,8 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
...
@@ -774,7 +778,8 @@ descriptors, e.g. module \code{fcntl} or \code{os.read()} and friends.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
tell
}{}
\begin{methoddesc}
[file]
{
tell
}{}
Return the file's current position, like
\code
{
stdio
}
's
\code
{
ftell()
}
.
Return the file's current position, like
\code
{
stdio
}
's
\cfunction
{
ftell()
}
.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
truncate
}{
\optional
{
size
}}
\begin{methoddesc}
[file]
{
truncate
}{
\optional
{
size
}}
...
@@ -788,13 +793,13 @@ operation).
...
@@ -788,13 +793,13 @@ operation).
\begin{methoddesc}
[file]
{
write
}{
str
}
\begin{methoddesc}
[file]
{
write
}{
str
}
Write a string to the file. There is no return value. Note: due to
Write a string to the file. There is no return value. Note: due to
buffering, the string may not actually show up in the file until
buffering, the string may not actually show up in the file until
the
\
code
{
flush()
}
or
\code
{
close()
}
method is called.
the
\
method
{
flush()
}
or
\method
{
close()
}
method is called.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
[file]
{
writelines
}{
list
}
\begin{methoddesc}
[file]
{
writelines
}{
list
}
Write a list of strings to the file. There is no return value.
Write a list of strings to the file. There is no return value.
(The name is intended to match
\
code
{
readlines
}
;
\code
{
writelines
}
(The name is intended to match
\
method
{
readlines()
}
;
does not add line separators.)
\method
{
writelines()
}
does not add line separators.)
\end{methoddesc}
\end{methoddesc}
File objects also offer the following attributes:
File objects also offer the following attributes:
...
@@ -823,9 +828,9 @@ attribute.
...
@@ -823,9 +828,9 @@ attribute.
Boolean that indicates whether a space character needs to be printed
Boolean that indicates whether a space character needs to be printed
before another value when using the
\keyword
{
print
}
statement.
before another value when using the
\keyword
{
print
}
statement.
Classes that are trying to simulate a file object should also have a
Classes that are trying to simulate a file object should also have a
writable
\
code
{
softspace
}
attribute, which should be initialized to
writable
\
member
{
softspace
}
attribute, which should be initialized to
zero. This will be automatic for classes implemented in Python; types
zero. This will be automatic for classes implemented in Python; types
implemented in
\C
{}
will have to provide a writable
\
code
{
softspace
}
implemented in
\C
{}
will have to provide a writable
\
member
{
softspace
}
attribute.
attribute.
\end{memberdesc}
\end{memberdesc}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment