[Python-checkins] python/dist/src/Doc/lib libfuncs.tex,1.100.4.12,1.100.4.13
fdrake@users.sourceforge.net
fdrake@users.sourceforge.net
2002年11月01日 13:34:41 -0800
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv17933
Modified Files:
Tag: release22-maint
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.100.4.12
retrieving revision 1.100.4.13
diff -C2 -d -r1.100.4.12 -r1.100.4.13
*** libfuncs.tex 6 Oct 2002 02:16:52 -0000 1.100.4.12
--- libfuncs.tex 1 Nov 2002 21:34:39 -0000 1.100.4.13
***************
*** 800,810 ****
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}
--- 800,821 ----
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}