[Python-checkins] python/dist/src/Doc/tut tut.tex,1.156.4.1.2.15,1.156.4.1.2.16

montanaro@users.sourceforge.net montanaro@users.sourceforge.net
Wed, 07 May 2003 08:29:56 -0700


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

Modified Files:
      Tag: release22-maint
	tut.tex 
Log Message:
replace most uses of `...` by repr(...), noting that `...` is discouraged,
but convenient in interactive sessions.


Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.156.4.1.2.15
retrieving revision 1.156.4.1.2.16
diff -C2 -d -r1.156.4.1.2.15 -r1.156.4.1.2.16
*** tut.tex	28 Oct 2002 19:30:45 -0000	1.156.4.1.2.15
--- tut.tex	7 May 2003 15:29:53 -0000	1.156.4.1.2.16
***************
*** 2748,2754 ****
  One question remains, of course: how do you convert values to strings?
  Luckily, Python has ways to convert any value to a string: pass it to
! the \function{repr()}  or \function{str()} functions, or just write
! the value between reverse quotes (\code{``}, equivalent to
! \function{repr()}).
  
  The \function{str()} function is meant to return representations of
--- 2748,2754 ----
  One question remains, of course: how do you convert values to strings?
  Luckily, Python has ways to convert any value to a string: pass it to
! the \function{repr()}  or \function{str()} functions.  Reverse quotes
! (\code{``}) are equivalent to \function{repr()}, but their use is
! discouraged.
  
  The \function{str()} function is meant to return representations of
***************
*** 2769,2794 ****
  >>> str(s)
  'Hello, world.'
! >>> `s`
  "'Hello, world.'"
  >>> str(0.1)
  '0.1'
! >>> `0.1`
  '0.10000000000000001'
  >>> x = 10 * 3.25
  >>> y = 200 * 200
! >>> s = 'The value of x is ' + `x` + ', and y is ' + `y` + '...'
  >>> print s
  The value of x is 32.5, and y is 40000...
! >>> # Reverse quotes work on other types besides numbers:
! ... p = [x, y]
! >>> ps = repr(p)
! >>> ps
! '[32.5, 40000]'
! >>> # Converting a string adds string quotes and backslashes:
  ... hello = 'hello, world\n'
! >>> hellos = `hello`
  >>> print hellos
  'hello, world\n'
! >>> # The argument of reverse quotes may be a tuple:
  ... `x, y, ('spam', 'eggs')`
  "(32.5, 40000, ('spam', 'eggs'))"
--- 2769,2792 ----
  >>> str(s)
  'Hello, world.'
! >>> repr(s)
  "'Hello, world.'"
  >>> str(0.1)
  '0.1'
! >>> repr(0.1)
  '0.10000000000000001'
  >>> x = 10 * 3.25
  >>> y = 200 * 200
! >>> s = 'The value of x is ' + repr(x) + ', and y is ' + repr(y) + '...'
  >>> print s
  The value of x is 32.5, and y is 40000...
! >>> # The repr() of a string adds string quotes and backslashes:
  ... hello = 'hello, world\n'
! >>> hellos = repr(hello)
  >>> print hellos
  'hello, world\n'
! >>> # The argument to repr() may be any Python object:
! ... repr(x, y, ('spam', 'eggs'))
! "(32.5, 40000, ('spam', 'eggs'))"
! >>> # reverse quotes are convenient in interactive sessions:
  ... `x, y, ('spam', 'eggs')`
  "(32.5, 40000, ('spam', 'eggs'))"
***************
*** 2800,2806 ****
  >>> import string
  >>> for x in range(1, 11):
! ...     print string.rjust(`x`, 2), string.rjust(`x*x`, 3),
  ...     # Note trailing comma on previous line
! ...     print string.rjust(`x*x*x`, 4)
  ...
   1   1    1
--- 2798,2804 ----
  >>> 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
***************
*** 3340,3344 ****
  ...         self.value = value
  ...     def __str__(self):
! ...         return `self.value`
  ... 
  >>> try:
--- 3338,3342 ----
  ...         self.value = value
  ...     def __str__(self):
! ...         return repr(self.value)
  ... 
  >>> try: