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
7974b0f2
Commit
7974b0f2
authored
Oct 05, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Documented __import__, callable, isinstance, issubclass,
and slice.
parent
df3dba04
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
10 deletions
+166
-10
Doc/lib/libfuncs.tex
Doc/lib/libfuncs.tex
+83
-5
Doc/libfuncs.tex
Doc/libfuncs.tex
+83
-5
No files found.
Doc/lib/libfuncs.tex
View file @
7974b0f2
...
@@ -5,10 +5,51 @@ are always available. They are listed here in alphabetical order.
...
@@ -5,10 +5,51 @@ are always available. They are listed here in alphabetical order.
\renewcommand
{
\indexsubitem
}{
(built-in function)
}
\renewcommand
{
\indexsubitem
}{
(built-in function)
}
\begin{funcdesc}
{__
import
__}{
name
\optional
{
, globals
\optional
{
, locals
\optional
{
, fromlist
}}}}
This function is invoked by the
\code
{
import
}
statement. It
mainly exists so that you can replace it with another
function that has a compatible interface, in order to change the
semantics of the
\code
{
import
}
statement. For examples of why and
how you would do this, see the standard library modules
\code
{
ni
}
,
\code
{
ihooks
}
and
\code
{
rexec
}
. See also the built-in module
\code
{
imp
}
, which defines some useful operations out of which you can
build your own
\code
{__
import
__}
function.
\stindex
{
import
}
\stmodindex
{
ni
}
\stmodindex
{
ihooks
}
\stmodindex
{
rexec
}
\bimodindex
{
imp
}
For example, the statement
\code
{
import spam
}
results in the following
call:
\code
{__
import
__
('spam', globals(), locals(), [])
}
;
the statement
\code
{
from spam.ham import eggs
}
results in
\code
{__
import
__
('spam.ham', globals(), locals(), ['eggs'])
}
.
Note that even though
\code
{
locals()
}
and
\code
{
['eggs']
}
are passed
in as arguments, the
\code
{__
import
__
()
}
function does not set the
local variable named
\code
{
eggs
}
; this is done by subsequent code that
is generated for the import statement. (In fact, the standard
implementation does not use its
\var
{
locals
}
argument at all, and uses
its
\var
{
globals
}
only to determine the package context of the
\code
{
import
}
statement.)
When the
\var
{
name
}
variable is of the form
\code
{
package.module
}
,
normally, the top-level package (the name up till the first dot) is
returned,
\emph
{
not
}
the module named by
\var
{
name
}
. However, when a
non-empty
\var
{
fromlist
}
argument is given, the module named by
\var
{
name
}
is returned. This is done for compatibility with the
bytecode generated for the different kinds of import statement; when
using
\code
{
import spam.ham.eggs
}
, the top-level package
\code
{
spam
}
must be placed in the importing namespace, but when using
\code
{
from
spam.ham import eggs
}
, the
\code
{
spam.ham
}
subpackage must be used to
find the
\code
{
eggs
}
variable.
\end{funcdesc}
\begin{funcdesc}
{
abs
}{
x
}
\begin{funcdesc}
{
abs
}{
x
}
Return the absolute value of a number. The argument may be a plain
Return the absolute value of a number. The argument may be a plain
or long integer or a floating point number. If the argument is a
or long integer or a floating point number. If the argument is a
complex number, its magnitude is returned.
complex number, its magnitude is returned.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
apply
}{
function
\,
args
\optional
{
, keywords
}}
\begin{funcdesc}
{
apply
}{
function
\,
args
\optional
{
, keywords
}}
...
@@ -24,6 +65,14 @@ dictionary whose keys are strings. It specifies keyword arguments to
...
@@ -24,6 +65,14 @@ dictionary whose keys are strings. It specifies keyword arguments to
be added to the end of the the argument list.
be added to the end of the the argument list.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
callable
}{
object
}
Return true if the
\var
{
object
}
argument appears callable, false if
not. If this returns true, it is still possible that a call fails,
but if it is false, calling
\var
{
object
}
will never succeed. Note
that classes are callable (calling a class returns a new instance);
class instances are callable if they have an attribute
\code
{__
call
__}
.
\end{funcdesc}
\begin{funcdesc}
{
chr
}{
i
}
\begin{funcdesc}
{
chr
}{
i
}
Return a string of one character whose
\ASCII
{}
code is the integer
Return a string of one character whose
\ASCII
{}
code is the integer
\var
{
i
}
, e.g.,
\code
{
chr(97)
}
returns the string
\code
{
'a'
}
. This is the
\var
{
i
}
, e.g.,
\code
{
chr(97)
}
returns the string
\code
{
'a'
}
. This is the
...
@@ -76,6 +125,9 @@ be added to the end of the the argument list.
...
@@ -76,6 +125,9 @@ be added to the end of the the argument list.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
dir
}{}
\begin{funcdesc}
{
dir
}{}
XXX New functionality takes anything and looks in
__
dict
__
,
__
methods
__
,
__
members
__
.
Without arguments, return the list of names in the current local
Without arguments, return the list of names in the current local
symbol table. With a module, class or class instance object as
symbol table. With a module, class or class instance object as
argument (or anything else that has a
\code
{__
dict
__}
attribute),
argument (or anything else that has a
\code
{__
dict
__}
attribute),
...
@@ -253,6 +305,20 @@ module from which it is called).
...
@@ -253,6 +305,20 @@ module from which it is called).
language definition should require truncation towards zero.
}
language definition should require truncation towards zero.
}
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
isinstance
}{
object, class
}
Return true if the
\var
{
object
}
argument is an instance of the
\var
{
class
}
argument, or of a (direct or indirect) subclass thereof.
If
\var
{
object
}
is not a class instance, the function always returns
false. If
\var
{
class
}
is not a class object, a
\code
{
TypeError
}
exception is raised.
\end{funcdesc}
\begin{funcdesc}
{
issubclass
}{
class1, class2
}
Return true if
\var
{
class1
}
is a subclass (direct or indirect) of
\var
{
class2
}
. A class is considered a subclass of itself. If either
argument is not a class object, a
\code
{
TypeError
}
exception is raised.
\end{funcdesc}
\begin{funcdesc}
{
len
}{
s
}
\begin{funcdesc}
{
len
}{
s
}
Return the length (the number of items) of an object. The argument
Return the length (the number of items) of an object. The argument
may be a sequence (string, tuple or list) or a mapping (dictionary).
may be a sequence (string, tuple or list) or a mapping (dictionary).
...
@@ -365,7 +431,7 @@ there's no reliable way to determine whether this is the case.}
...
@@ -365,7 +431,7 @@ there's no reliable way to determine whether this is the case.}
35000)
}
is not allowed.
35000)
}
is not allowed.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
range
}{
\optional
{
start
\,
}
end
\optional
{
\,
step
}}
\begin{funcdesc}
{
range
}{
\optional
{
start
\,
}
stop
\optional
{
\,
step
}}
This is a versatile function to create lists containing arithmetic
This is a versatile function to create lists containing arithmetic
progressions. It is most often used in
\code
{
for
}
loops. The
progressions. It is most often used in
\code
{
for
}
loops. The
arguments must be plain integers. If the
\var
{
step
}
argument is
arguments must be plain integers. If the
\var
{
step
}
argument is
...
@@ -374,9 +440,9 @@ there's no reliable way to determine whether this is the case.}
...
@@ -374,9 +440,9 @@ there's no reliable way to determine whether this is the case.}
plain integers
\code
{
[
\var
{
start
}
,
\var
{
start
}
+
\var
{
step
}
,
plain integers
\code
{
[
\var
{
start
}
,
\var
{
start
}
+
\var
{
step
}
,
\var
{
start
}
+ 2 *
\var
{
step
}
,
\ldots
]
}
. If
\var
{
step
}
is positive,
\var
{
start
}
+ 2 *
\var
{
step
}
,
\ldots
]
}
. If
\var
{
step
}
is positive,
the last element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
the last element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
\var
{
step
}}
less than
\var
{
end
}
; if
\var
{
step
}
is negative, the last
\var
{
step
}}
less than
\var
{
stop
}
; if
\var
{
step
}
is negative, the last
element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
\var
{
step
}}
element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
\var
{
step
}}
greater than
\var
{
end
}
.
\var
{
step
}
must not be zero (or else an
greater than
\var
{
stop
}
.
\var
{
step
}
must not be zero (or else an
exception is raised). Example:
exception is raised). Example:
\bcode
\begin{verbatim}
\bcode
\begin{verbatim}
...
@@ -499,6 +565,18 @@ when passed to \code{eval()}.
...
@@ -499,6 +565,18 @@ when passed to \code{eval()}.
\code
{
\var
{
x
}
.
\var
{
foobar
}
= 123
}
.
\code
{
\var
{
x
}
.
\var
{
foobar
}
= 123
}
.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
slice
}{
\optional
{
start
\,
}
stop
\optional
{
\,
step
}}
Return a slice object representing the set of indices specified by
\code
{
range(
\var
{
start
}
,
\var
{
stop
}
,
\var
{
step
}
)
}
. The
\var
{
start
}
and
\var
{
step
}
arguments default to None. Slice objects have
read-only data attributes
\code
{
start
}
,
\code
{
stop
}
and
\code
{
step
}
which merely return the argument values (or their default). They have
no other explicit functionality; however they are used by Numerical
Python and other third party extensions. Slice objects are also
generated when extended indexing syntax is used, e.g. for
\code
{
a[start:stop:step]
}
or
\code
{
a[start:stop, i]
}
.
\end{funcdesc}
\begin{funcdesc}
{
str
}{
object
}
\begin{funcdesc}
{
str
}{
object
}
Return a string containing a nicely printable representation of an
Return a string containing a nicely printable representation of an
object. For strings, this returns the string itself. The difference
object. For strings, this returns the string itself. The difference
...
@@ -541,7 +619,7 @@ cannot normally be affected this way, but variables retrieved from
...
@@ -541,7 +619,7 @@ cannot normally be affected this way, but variables retrieved from
other scopes (e.g. modules) can be. This may change.
}
other scopes (e.g. modules) can be. This may change.
}
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
xrange
}{
\optional
{
start
\,
}
end
\optional
{
\,
step
}}
\begin{funcdesc}
{
xrange
}{
\optional
{
start
\,
}
stop
\optional
{
\,
step
}}
This function is very similar to
\code
{
range()
}
, but returns an
This function is very similar to
\code
{
range()
}
, but returns an
``xrange object'' instead of a list. This is an opaque sequence type
``xrange object'' instead of a list. This is an opaque sequence type
which yields the same values as the corresponding list, without
which yields the same values as the corresponding list, without
...
...
Doc/libfuncs.tex
View file @
7974b0f2
...
@@ -5,10 +5,51 @@ are always available. They are listed here in alphabetical order.
...
@@ -5,10 +5,51 @@ are always available. They are listed here in alphabetical order.
\renewcommand
{
\indexsubitem
}{
(built-in function)
}
\renewcommand
{
\indexsubitem
}{
(built-in function)
}
\begin{funcdesc}
{__
import
__}{
name
\optional
{
, globals
\optional
{
, locals
\optional
{
, fromlist
}}}}
This function is invoked by the
\code
{
import
}
statement. It
mainly exists so that you can replace it with another
function that has a compatible interface, in order to change the
semantics of the
\code
{
import
}
statement. For examples of why and
how you would do this, see the standard library modules
\code
{
ni
}
,
\code
{
ihooks
}
and
\code
{
rexec
}
. See also the built-in module
\code
{
imp
}
, which defines some useful operations out of which you can
build your own
\code
{__
import
__}
function.
\stindex
{
import
}
\stmodindex
{
ni
}
\stmodindex
{
ihooks
}
\stmodindex
{
rexec
}
\bimodindex
{
imp
}
For example, the statement
\code
{
import spam
}
results in the following
call:
\code
{__
import
__
('spam', globals(), locals(), [])
}
;
the statement
\code
{
from spam.ham import eggs
}
results in
\code
{__
import
__
('spam.ham', globals(), locals(), ['eggs'])
}
.
Note that even though
\code
{
locals()
}
and
\code
{
['eggs']
}
are passed
in as arguments, the
\code
{__
import
__
()
}
function does not set the
local variable named
\code
{
eggs
}
; this is done by subsequent code that
is generated for the import statement. (In fact, the standard
implementation does not use its
\var
{
locals
}
argument at all, and uses
its
\var
{
globals
}
only to determine the package context of the
\code
{
import
}
statement.)
When the
\var
{
name
}
variable is of the form
\code
{
package.module
}
,
normally, the top-level package (the name up till the first dot) is
returned,
\emph
{
not
}
the module named by
\var
{
name
}
. However, when a
non-empty
\var
{
fromlist
}
argument is given, the module named by
\var
{
name
}
is returned. This is done for compatibility with the
bytecode generated for the different kinds of import statement; when
using
\code
{
import spam.ham.eggs
}
, the top-level package
\code
{
spam
}
must be placed in the importing namespace, but when using
\code
{
from
spam.ham import eggs
}
, the
\code
{
spam.ham
}
subpackage must be used to
find the
\code
{
eggs
}
variable.
\end{funcdesc}
\begin{funcdesc}
{
abs
}{
x
}
\begin{funcdesc}
{
abs
}{
x
}
Return the absolute value of a number. The argument may be a plain
Return the absolute value of a number. The argument may be a plain
or long integer or a floating point number. If the argument is a
or long integer or a floating point number. If the argument is a
complex number, its magnitude is returned.
complex number, its magnitude is returned.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
apply
}{
function
\,
args
\optional
{
, keywords
}}
\begin{funcdesc}
{
apply
}{
function
\,
args
\optional
{
, keywords
}}
...
@@ -24,6 +65,14 @@ dictionary whose keys are strings. It specifies keyword arguments to
...
@@ -24,6 +65,14 @@ dictionary whose keys are strings. It specifies keyword arguments to
be added to the end of the the argument list.
be added to the end of the the argument list.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
callable
}{
object
}
Return true if the
\var
{
object
}
argument appears callable, false if
not. If this returns true, it is still possible that a call fails,
but if it is false, calling
\var
{
object
}
will never succeed. Note
that classes are callable (calling a class returns a new instance);
class instances are callable if they have an attribute
\code
{__
call
__}
.
\end{funcdesc}
\begin{funcdesc}
{
chr
}{
i
}
\begin{funcdesc}
{
chr
}{
i
}
Return a string of one character whose
\ASCII
{}
code is the integer
Return a string of one character whose
\ASCII
{}
code is the integer
\var
{
i
}
, e.g.,
\code
{
chr(97)
}
returns the string
\code
{
'a'
}
. This is the
\var
{
i
}
, e.g.,
\code
{
chr(97)
}
returns the string
\code
{
'a'
}
. This is the
...
@@ -76,6 +125,9 @@ be added to the end of the the argument list.
...
@@ -76,6 +125,9 @@ be added to the end of the the argument list.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
dir
}{}
\begin{funcdesc}
{
dir
}{}
XXX New functionality takes anything and looks in
__
dict
__
,
__
methods
__
,
__
members
__
.
Without arguments, return the list of names in the current local
Without arguments, return the list of names in the current local
symbol table. With a module, class or class instance object as
symbol table. With a module, class or class instance object as
argument (or anything else that has a
\code
{__
dict
__}
attribute),
argument (or anything else that has a
\code
{__
dict
__}
attribute),
...
@@ -253,6 +305,20 @@ module from which it is called).
...
@@ -253,6 +305,20 @@ module from which it is called).
language definition should require truncation towards zero.
}
language definition should require truncation towards zero.
}
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
isinstance
}{
object, class
}
Return true if the
\var
{
object
}
argument is an instance of the
\var
{
class
}
argument, or of a (direct or indirect) subclass thereof.
If
\var
{
object
}
is not a class instance, the function always returns
false. If
\var
{
class
}
is not a class object, a
\code
{
TypeError
}
exception is raised.
\end{funcdesc}
\begin{funcdesc}
{
issubclass
}{
class1, class2
}
Return true if
\var
{
class1
}
is a subclass (direct or indirect) of
\var
{
class2
}
. A class is considered a subclass of itself. If either
argument is not a class object, a
\code
{
TypeError
}
exception is raised.
\end{funcdesc}
\begin{funcdesc}
{
len
}{
s
}
\begin{funcdesc}
{
len
}{
s
}
Return the length (the number of items) of an object. The argument
Return the length (the number of items) of an object. The argument
may be a sequence (string, tuple or list) or a mapping (dictionary).
may be a sequence (string, tuple or list) or a mapping (dictionary).
...
@@ -365,7 +431,7 @@ there's no reliable way to determine whether this is the case.}
...
@@ -365,7 +431,7 @@ there's no reliable way to determine whether this is the case.}
35000)
}
is not allowed.
35000)
}
is not allowed.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
range
}{
\optional
{
start
\,
}
end
\optional
{
\,
step
}}
\begin{funcdesc}
{
range
}{
\optional
{
start
\,
}
stop
\optional
{
\,
step
}}
This is a versatile function to create lists containing arithmetic
This is a versatile function to create lists containing arithmetic
progressions. It is most often used in
\code
{
for
}
loops. The
progressions. It is most often used in
\code
{
for
}
loops. The
arguments must be plain integers. If the
\var
{
step
}
argument is
arguments must be plain integers. If the
\var
{
step
}
argument is
...
@@ -374,9 +440,9 @@ there's no reliable way to determine whether this is the case.}
...
@@ -374,9 +440,9 @@ there's no reliable way to determine whether this is the case.}
plain integers
\code
{
[
\var
{
start
}
,
\var
{
start
}
+
\var
{
step
}
,
plain integers
\code
{
[
\var
{
start
}
,
\var
{
start
}
+
\var
{
step
}
,
\var
{
start
}
+ 2 *
\var
{
step
}
,
\ldots
]
}
. If
\var
{
step
}
is positive,
\var
{
start
}
+ 2 *
\var
{
step
}
,
\ldots
]
}
. If
\var
{
step
}
is positive,
the last element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
the last element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
\var
{
step
}}
less than
\var
{
end
}
; if
\var
{
step
}
is negative, the last
\var
{
step
}}
less than
\var
{
stop
}
; if
\var
{
step
}
is negative, the last
element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
\var
{
step
}}
element is the largest
\code
{
\var
{
start
}
+
\var
{
i
}
*
\var
{
step
}}
greater than
\var
{
end
}
.
\var
{
step
}
must not be zero (or else an
greater than
\var
{
stop
}
.
\var
{
step
}
must not be zero (or else an
exception is raised). Example:
exception is raised). Example:
\bcode
\begin{verbatim}
\bcode
\begin{verbatim}
...
@@ -499,6 +565,18 @@ when passed to \code{eval()}.
...
@@ -499,6 +565,18 @@ when passed to \code{eval()}.
\code
{
\var
{
x
}
.
\var
{
foobar
}
= 123
}
.
\code
{
\var
{
x
}
.
\var
{
foobar
}
= 123
}
.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
slice
}{
\optional
{
start
\,
}
stop
\optional
{
\,
step
}}
Return a slice object representing the set of indices specified by
\code
{
range(
\var
{
start
}
,
\var
{
stop
}
,
\var
{
step
}
)
}
. The
\var
{
start
}
and
\var
{
step
}
arguments default to None. Slice objects have
read-only data attributes
\code
{
start
}
,
\code
{
stop
}
and
\code
{
step
}
which merely return the argument values (or their default). They have
no other explicit functionality; however they are used by Numerical
Python and other third party extensions. Slice objects are also
generated when extended indexing syntax is used, e.g. for
\code
{
a[start:stop:step]
}
or
\code
{
a[start:stop, i]
}
.
\end{funcdesc}
\begin{funcdesc}
{
str
}{
object
}
\begin{funcdesc}
{
str
}{
object
}
Return a string containing a nicely printable representation of an
Return a string containing a nicely printable representation of an
object. For strings, this returns the string itself. The difference
object. For strings, this returns the string itself. The difference
...
@@ -541,7 +619,7 @@ cannot normally be affected this way, but variables retrieved from
...
@@ -541,7 +619,7 @@ cannot normally be affected this way, but variables retrieved from
other scopes (e.g. modules) can be. This may change.
}
other scopes (e.g. modules) can be. This may change.
}
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
xrange
}{
\optional
{
start
\,
}
end
\optional
{
\,
step
}}
\begin{funcdesc}
{
xrange
}{
\optional
{
start
\,
}
stop
\optional
{
\,
step
}}
This function is very similar to
\code
{
range()
}
, but returns an
This function is very similar to
\code
{
range()
}
, but returns an
``xrange object'' instead of a list. This is an opaque sequence type
``xrange object'' instead of a list. This is an opaque sequence type
which yields the same values as the corresponding list, without
which yields the same values as the corresponding list, without
...
...
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