[Python-checkins] python/dist/src/Doc/lib libfuncs.tex,1.118,1.119
fdrake@users.sourceforge.net
fdrake@users.sourceforge.net
Fri, 01 Nov 2002 13:33:49 -0800
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv17429
Modified Files:
libfuncs.tex
Log Message:
Update example for the type() function to use the currently accepted
preference of using "is" instead of "==" to compare types, use
built-in names where available, and point to the isinstance()
function.
Closes SF bug #632196.
Index: libfuncs.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libfuncs.tex,v
retrieving revision 1.118
retrieving revision 1.119
diff -C2 -d -r1.118 -r1.119
*** libfuncs.tex 22 Oct 2002 20:31:22 -0000 1.118
--- libfuncs.tex 1 Nov 2002 21:33:44 -0000 1.119
***************
*** 837,847 ****
type\obindex{type} object. The standard module
\module{types}\refstmodindex{types} defines names for all built-in
! types.
For instance:
\begin{verbatim}
>>> import types
! >>> if type(x) == types.StringType: print "It's a string"
\end{verbatim}
\end{funcdesc}
--- 837,858 ----
type\obindex{type} object. The standard module
\module{types}\refstmodindex{types} defines names for all built-in
! types that don't already have built-in names.
For instance:
\begin{verbatim}
>>> import types
! >>> x = 'abc'
! >>> if type(x) is str: print "It's a string"
! ...
! It's a string
! >>> def f(): pass
! ...
! >>> if type(f) is types.FunctionType: print "It's a function"
! ...
! It's a function
\end{verbatim}
+
+ The \function{isinstance()} built-in function is recommended for
+ testing the type of an object.
\end{funcdesc}