[Python-checkins] python/dist/src/Doc/tut tut.tex,1.203,1.204

fdrake at users.sourceforge.net fdrake at users.sourceforge.net
Thu Sep 11 00:06:29 EDT 2003


Update of /cvsroot/python/python/dist/src/Doc/tut
In directory sc8-pr-cvs1:/tmp/cvs-serv2102

Modified Files:
	tut.tex 
Log Message:
- added many links into the library reference
- removed use of the string module
- fixed some broken markup


Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.203
retrieving revision 1.204
diff -C2 -d -r1.203 -r1.204
*** tut.tex	11 Sep 2003 04:28:13 -0000	1.203
--- tut.tex	11 Sep 2003 06:06:26 -0000	1.204
***************
*** 658,670 ****
  
  \begin{verbatim}
- >>> import string
  >>> 'str' 'ing'                   #  <-  This is ok
  'string'
! >>> string.strip('str') + 'ing'   #  <-  This is ok
  'string'
! >>> string.strip('str') 'ing'     #  <-  This is invalid
    File "<stdin>", line 1, in ?
!     string.strip('str') 'ing'
!                             ^
  SyntaxError: invalid syntax
  \end{verbatim}
--- 658,669 ----
  
  \begin{verbatim}
  >>> 'str' 'ing'                   #  <-  This is ok
  'string'
! >>> 'str'.strip() + 'ing'   #  <-  This is ok
  'string'
! >>> 'str'.strip() 'ing'     #  <-  This is invalid
    File "<stdin>", line 1, in ?
!     'str'.strip() 'ing'
!                       ^
  SyntaxError: invalid syntax
  \end{verbatim}
***************
*** 808,811 ****
--- 807,825 ----
  
  
+ \begin{seealso}
+   \seetitle[../lib/typesseq.html]{Sequence Types}%
+            {Strings, and the Unicode strings described in the next
+             section, are examples of \emph{sequence types}, and
+             support the common operations supported by such types.}
+   \seetitle[../lib/string-methods.html]{String Methods}%
+            {Both strings and Unicode strings support a large number of
+             methods for basic transformations and searching.}
+   \seetitle[../lib/typesseq-strings.html]{String Formatting Operations}%
+            {The formatting operations invoked when strings and Unicode
+             strings are the left operand of the \code{\%} operator are
+             described in more detail here.}
+ \end{seealso}
+ 
+ 
  \subsection{Unicode Strings \label{unicodeStrings}}
  \sectionauthor{Marc-Andre Lemburg}{mal at lemburg.com}
***************
*** 1517,1521 ****
  
  When a final formal parameter of the form \code{**\var{name}} is
! present, it receives a dictionary containing all keyword arguments
  whose keyword doesn't correspond to a formal parameter.  This may be
  combined with a formal parameter of the form
--- 1531,1535 ----
  
  When a final formal parameter of the form \code{**\var{name}} is
! present, it receives a \ulink{dictionary}{../lib/typesmapping.html} containing all keyword arguments
  whose keyword doesn't correspond to a formal parameter.  This may be
  combined with a formal parameter of the form
***************
*** 1979,1985 ****
  We saw that lists and strings have many common properties, such as
  indexing and slicing operations.  They are two examples of
! \emph{sequence} data types.  Since Python is an evolving language,
! other sequence data types may be added.  There is also another
! standard sequence data type: the \emph{tuple}.
  
  A tuple consists of a number of values separated by commas, for
--- 1993,2000 ----
  We saw that lists and strings have many common properties, such as
  indexing and slicing operations.  They are two examples of
! \ulink{\emph{sequence} data types}{../lib/typesseq.html}.  Since
! Python is an evolving language, other sequence data types may be
! added.  There is also another standard sequence data type: the
! \emph{tuple}.
  
  A tuple consists of a number of values separated by commas, for
***************
*** 2051,2055 ****
  \section{Dictionaries \label{dictionaries}}
  
! Another useful data type built into Python is the \emph{dictionary}.
  Dictionaries are sometimes found in other languages as ``associative
  memories'' or ``associative arrays''.  Unlike sequences, which are
--- 2066,2071 ----
  \section{Dictionaries \label{dictionaries}}
  
! Another useful data type built into Python is the
! \ulink{\emph{dictionary}}{../lib/typesmapping.html}.
  Dictionaries are sometimes found in other languages as ``associative
  memories'' or ``associative arrays''.  Unlike sequences, which are
***************
*** 2079,2087 ****
  value using a non-existent key.
  
! The \code{keys()} method of a dictionary object returns a list of all
  the keys used in the dictionary, in random order (if you want it
! sorted, just apply the \code{sort()} method to the list of keys).  To
  check whether a single key is in the dictionary, use the
! \code{has_key()} method of the dictionary.
  
  Here is a small example using a dictionary:
--- 2095,2103 ----
  value using a non-existent key.
  
! The \method{keys()} method of a dictionary object returns a list of all
  the keys used in the dictionary, in random order (if you want it
! sorted, just apply the \method{sort()} method to the list of keys).  To
  check whether a single key is in the dictionary, use the
! \method{has_key()} method of the dictionary.
  
  Here is a small example using a dictionary:
***************
*** 2873,2881 ****
  
  \begin{verbatim}
- >>> import string
  >>> for x in range(1, 11):
! ...     print string.rjust(repr(x), 2), string.rjust(repr(x*x), 3),
  ...     # Note trailing comma on previous line
! ...     print string.rjust(repr(x*x*x), 4)
  ...
   1   1    1
--- 2889,2896 ----
  
  \begin{verbatim}
  >>> for x in range(1, 11):
! ...     print repr(x).rjust(2), repr(x*x).rjust(3),
  ...     # Note trailing comma on previous line
! ...     print repr(x*x*x).rjust(4)
  ...
   1   1    1
***************
*** 2907,2932 ****
  \keyword{print} works: it always adds spaces between its arguments.)
  
! This example demonstrates the function \function{string.rjust()},
  which right-justifies a string in a field of a given width by padding
! it with spaces on the left.  There are similar functions
! \function{string.ljust()} and \function{string.center()}.  These
! functions do not write anything, they just return a new string.  If
  the input string is too long, they don't truncate it, but return it
  unchanged; this will mess up your column lay-out but that's usually
  better than the alternative, which would be lying about a value.  (If
  you really want truncation you can always add a slice operation, as in
! \samp{string.ljust(x,~n)[0:n]}.)
  
! There is another function, \function{string.zfill()}, which pads a
  numeric string on the left with zeros.  It understands about plus and
  minus signs:
  
  \begin{verbatim}
! >>> import string
! >>> string.zfill('12', 5)
  '00012'
! >>> string.zfill('-3.14', 7)
  '-003.14'
! >>> string.zfill('3.14159265359', 5)
  '3.14159265359'
  \end{verbatim}
--- 2922,2946 ----
  \keyword{print} works: it always adds spaces between its arguments.)
  
! This example demonstrates the \method{rjust()} method of string objects,
  which right-justifies a string in a field of a given width by padding
! it with spaces on the left.  There are similar methods
! \method{ljust()} and \method{center()}.  These
! methods do not write anything, they just return a new string.  If
  the input string is too long, they don't truncate it, but return it
  unchanged; this will mess up your column lay-out but that's usually
  better than the alternative, which would be lying about a value.  (If
  you really want truncation you can always add a slice operation, as in
! \samp{x.ljust(~n)[:n]}.)
  
! There is another method, \method{zfill()}, which pads a
  numeric string on the left with zeros.  It understands about plus and
  minus signs:
  
  \begin{verbatim}
! >>> '12'.zfill(5)
  '00012'
! >>> '-3.14'.zfill(7)
  '-003.14'
! >>> '3.14159265359'.zfill(5)
  '3.14159265359'
  \end{verbatim}
***************
*** 3111,3115 ****
  bit more effort, since the \method{read()} method only returns
  strings, which will have to be passed to a function like
! \function{string.atoi()}, which takes a string like \code{'123'} and
  returns its numeric value 123.  However, when you want to save more
  complex data types like lists, dictionaries, or class instances,
--- 3125,3129 ----
  bit more effort, since the \method{read()} method only returns
  strings, which will have to be passed to a function like
! \function{int()}, which takes a string like \code{'123'} and
  returns its numeric value 123.  However, when you want to save more
  complex data types like lists, dictionaries, or class instances,
***************
*** 3298,3307 ****
  
  \begin{verbatim}
! import string, sys
  
  try:
      f = open('myfile.txt')
      s = f.readline()
!     i = int(string.strip(s))
  except IOError, (errno, strerror):
      print "I/O error(%s): %s" % (errno, strerror)
--- 3312,3321 ----
  
  \begin{verbatim}
! import sys
  
  try:
      f = open('myfile.txt')
      s = f.readline()
!     i = int(s.strip())
  except IOError, (errno, strerror):
      print "I/O error(%s): %s" % (errno, strerror)
***************
*** 4467,4471 ****
  
  in your \file{\~{}/.inputrc}.  (Of course, this makes it harder to
! type indented continuation lines.)
  
  Automatic completion of variable and module names is optionally
--- 4481,4486 ----
  
  in your \file{\~{}/.inputrc}.  (Of course, this makes it harder to
! type indented continuation lines if you're accustomed to using
! \kbd{Tab} for that purpose.)
  
  Automatic completion of variable and module names is optionally





More information about the Python-checkins mailing list