[Python-3000-checkins] r63200 - in python/branches/py3k: Doc/howto/functional.rst Doc/library/collections.rst Doc/library/datetime.rst Doc/library/json.rst Doc/library/modulefinder.rst Doc/library/plistlib.rst Doc/library/sched.rst Doc/library/socket.rst Doc/library/wsgiref.rst Doc/tools/sphinxext/patchlevel.py Doc/tutorial/datastructures.rst Doc/tutorial/errors.rst Lib/bsddb/dbrecio.py Lib/idlelib/PyShell.py Lib/os.py Lib/pdb.py Lib/test/test_global.py Lib/test/test_popen.py Lib/test/test_support.py Lib/test/test_tokenize.py

neal.norwitz python-3000-checkins at python.org
Tue May 13 06:55:25 CEST 2008


Author: neal.norwitz
Date: Tue May 13 06:55:24 2008
New Revision: 63200

Log:
Convert a lot of print statements to print functions in docstrings,
documentation, and unused/rarely used functions.


Modified:
   python/branches/py3k/Doc/howto/functional.rst
   python/branches/py3k/Doc/library/collections.rst
   python/branches/py3k/Doc/library/datetime.rst
   python/branches/py3k/Doc/library/json.rst
   python/branches/py3k/Doc/library/modulefinder.rst
   python/branches/py3k/Doc/library/plistlib.rst
   python/branches/py3k/Doc/library/sched.rst
   python/branches/py3k/Doc/library/socket.rst
   python/branches/py3k/Doc/library/wsgiref.rst
   python/branches/py3k/Doc/tools/sphinxext/patchlevel.py
   python/branches/py3k/Doc/tutorial/datastructures.rst
   python/branches/py3k/Doc/tutorial/errors.rst
   python/branches/py3k/Lib/bsddb/dbrecio.py
   python/branches/py3k/Lib/idlelib/PyShell.py
   python/branches/py3k/Lib/os.py
   python/branches/py3k/Lib/pdb.py
   python/branches/py3k/Lib/test/test_global.py
   python/branches/py3k/Lib/test/test_popen.py
   python/branches/py3k/Lib/test/test_support.py
   python/branches/py3k/Lib/test/test_tokenize.py

Modified: python/branches/py3k/Doc/howto/functional.rst
==============================================================================
--- python/branches/py3k/Doc/howto/functional.rst	(original)
+++ python/branches/py3k/Doc/howto/functional.rst	Tue May 13 06:55:24 2008
@@ -222,10 +222,10 @@
 
 
     for i in iter(obj):
-        print i
+        print(i)
 
     for i in obj:
-        print i
+        print(i)
 
 Iterators can be materialized as lists or tuples by using the :func:`list` or
 :func:`tuple` constructor functions:
@@ -709,7 +709,7 @@
 containing the count and each element. ::
 
     >>> for item in enumerate(['subject', 'verb', 'object']):
-    ...     print item
+    ...     print(item)
     (0, 'subject')
     (1, 'verb')
     (2, 'object')

Modified: python/branches/py3k/Doc/library/collections.rst
==============================================================================
--- python/branches/py3k/Doc/library/collections.rst	(original)
+++ python/branches/py3k/Doc/library/collections.rst	Tue May 13 06:55:24 2008
@@ -232,7 +232,7 @@
    >>> from collections import deque
    >>> d = deque('ghi')                 # make a new deque with three items
    >>> for elem in d:                   # iterate over the deque's elements
-   ...     print elem.upper()
+   ...     print(elem.upper())
    G
    H
    I

Modified: python/branches/py3k/Doc/library/datetime.rst
==============================================================================
--- python/branches/py3k/Doc/library/datetime.rst	(original)
+++ python/branches/py3k/Doc/library/datetime.rst	Tue May 13 06:55:24 2008
@@ -532,7 +532,7 @@
     datetime.date(2002, 3, 11)
     >>> t = d.timetuple()
     >>> for i in t:     # doctest: +SKIP
-    ...     print i
+    ...     print(i)
     2002                # year
     3                   # month
     11                  # day
@@ -544,7 +544,7 @@
     -1
     >>> ic = d.isocalendar()
     >>> for i in ic:    # doctest: +SKIP
-    ...     print i
+    ...     print(i)
     2002                # ISO year
     11                  # ISO week number
     1                   # ISO day number ( 1 = Monday )
@@ -1011,7 +1011,7 @@
     >>> # Using datetime.timetuple() to get tuple of all attributes
     >>> tt = dt.timetuple()
     >>> for it in tt:   # doctest: +SKIP
-    ...     print it
+    ...     print(it)
     ... 
     2006    # year
     11      # month
@@ -1025,7 +1025,7 @@
     >>> # Date in ISO format
     >>> ic = dt.isocalendar()
     >>> for it in ic:   # doctest: +SKIP
-    ...     print it
+    ...     print(it)
     ...
     2006    # ISO year
     47      # ISO week

Modified: python/branches/py3k/Doc/library/json.rst
==============================================================================
--- python/branches/py3k/Doc/library/json.rst	(original)
+++ python/branches/py3k/Doc/library/json.rst	Tue May 13 06:55:24 2008
@@ -17,13 +17,13 @@
     >>> import json
     >>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
     '["foo", {"bar": ["baz", null, 1.0, 2]}]'
-    >>> print json.dumps("\"foo\bar")
+    >>> print(json.dumps("\"foo\bar"))
     "\"foo\bar"
-    >>> print json.dumps(u'\u1234')
+    >>> print(json.dumps(u'\u1234'))
     "\u1234"
-    >>> print json.dumps('\\')
+    >>> print(json.dumps('\\'))
     "\\"
-    >>> print json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)
+    >>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True))
     {"a": 0, "b": 0, "c": 0}
     >>> from StringIO import StringIO
     >>> io = StringIO()
@@ -40,7 +40,7 @@
 Pretty printing::
 
     >>> import json
-    >>> print json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
+    >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4))
     {
         "4": 5, 
         "6": 7

Modified: python/branches/py3k/Doc/library/modulefinder.rst
==============================================================================
--- python/branches/py3k/Doc/library/modulefinder.rst	(original)
+++ python/branches/py3k/Doc/library/modulefinder.rst	Tue May 13 06:55:24 2008
@@ -32,7 +32,7 @@
    This class provides :meth:`run_script` and :meth:`report` methods to determine
    the set of modules imported by a script. *path* can be a list of directories to
    search for modules; if not specified, ``sys.path`` is used.  *debug* sets the
-   debugging level; higher values make the class print  debugging messages about
+   debugging level; higher values make the class print debugging messages about
    what it's doing. *excludes* is a list of module names to exclude from the
    analysis. *replace_paths* is a list of ``(oldpath, newpath)`` tuples that will
    be replaced in module paths.
@@ -82,14 +82,14 @@
    finder = ModuleFinder()
    finder.run_script('bacon.py')
 
-   print 'Loaded modules:'
-   for name, mod in finder.modules.iteritems():
-       print '%s: ' % name,
-       print ','.join(mod.globalnames.keys()[:3])
-
-   print '-'*50
-   print 'Modules not imported:'
-   print '\n'.join(finder.badmodules.iterkeys())
+   print('Loaded modules:')
+   for name, mod in finder.modules.items():
+       print('%s: ' % name, end='')
+       print(','.join(mod.globalnames.keys()[:3]))
+
+   print('-'*50)
+   print('Modules not imported:')
+   print('\n'.join(finder.badmodules.keys()))
 
 Sample output (may vary depending on the architecture)::
 

Modified: python/branches/py3k/Doc/library/plistlib.rst
==============================================================================
--- python/branches/py3k/Doc/library/plistlib.rst	(original)
+++ python/branches/py3k/Doc/library/plistlib.rst	Tue May 13 06:55:24 2008
@@ -104,4 +104,4 @@
 Parsing a plist::
 
     pl = readPlist(pathOrFile)
-    print pl["aKey"]
+    print(pl["aKey"])

Modified: python/branches/py3k/Doc/library/sched.rst
==============================================================================
--- python/branches/py3k/Doc/library/sched.rst	(original)
+++ python/branches/py3k/Doc/library/sched.rst	Tue May 13 06:55:24 2008
@@ -52,14 +52,14 @@
     >>> import time
     >>> from threading import Timer
     >>> def print_time():
-    ...     print "From print_time", time.time()
+    ...     print("From print_time", time.time())
     ...
     >>> def print_some_times():
-    ...     print time.time()
+    ...     print(time.time())
     ...     Timer(5, print_time, ()).start()
     ...     Timer(10, print_time, ()).start()
     ...     time.sleep(11)	# sleep while time-delay events execute
-    ...     print time.time()     
+    ...     print(time.time())
     ...
     >>> print_some_times()
     930343690.257

Modified: python/branches/py3k/Doc/library/socket.rst
==============================================================================
--- python/branches/py3k/Doc/library/socket.rst	(original)
+++ python/branches/py3k/Doc/library/socket.rst	Tue May 13 06:55:24 2008
@@ -866,7 +866,7 @@
    s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
    
    # receive a package
-   print s.recvfrom(65565)
+   print(s.recvfrom(65565))
    
    # disabled promiscuous mode
    s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)

Modified: python/branches/py3k/Doc/library/wsgiref.rst
==============================================================================
--- python/branches/py3k/Doc/library/wsgiref.rst	(original)
+++ python/branches/py3k/Doc/library/wsgiref.rst	Tue May 13 06:55:24 2008
@@ -132,7 +132,7 @@
           return ret
 
       httpd = make_server('', 8000, simple_app)
-      print "Serving on port 8000..."
+      print("Serving on port 8000...")
       httpd.serve_forever()
 
 

Modified: python/branches/py3k/Doc/tools/sphinxext/patchlevel.py
==============================================================================
--- python/branches/py3k/Doc/tools/sphinxext/patchlevel.py	(original)
+++ python/branches/py3k/Doc/tools/sphinxext/patchlevel.py	Tue May 13 06:55:24 2008
@@ -63,9 +63,10 @@
         return get_header_version_info('.')
     except (IOError, OSError):
         version, release = get_sys_version_info()
-        print >>sys.stderr, 'Can\'t get version info from Include/patchlevel.h, ' \
-              'using version of this interpreter (%s).' % release
+        print('Can\'t get version info from Include/patchlevel.h, '
+              'using version of this interpreter (%s).' % release,
+              file=sys.stderr)
         return version, release
 
 if __name__ == '__main__':
-    print get_header_version_info('.')[1]
+    print(get_header_version_info('.')[1])

Modified: python/branches/py3k/Doc/tutorial/datastructures.rst
==============================================================================
--- python/branches/py3k/Doc/tutorial/datastructures.rst	(original)
+++ python/branches/py3k/Doc/tutorial/datastructures.rst	Tue May 13 06:55:24 2008
@@ -239,7 +239,7 @@
 Now, if you wanted to swap rows and columns, you could use a list 
 comprehension::
 
-    >>> print [[row[i] for row in mat] for i in [0, 1, 2]]
+    >>> print([[row[i] for row in mat] for i in [0, 1, 2]])
     [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
 
 Special care has to be taken for the *nested* list comprehension:
@@ -251,7 +251,7 @@
 
     for i in [0, 1, 2]:
         for row in mat:
-            print row[i],
+            print(row[i], end="")
         print
 
 In real world, you should prefer builtin functions to complex flow statements. 

Modified: python/branches/py3k/Doc/tutorial/errors.rst
==============================================================================
--- python/branches/py3k/Doc/tutorial/errors.rst	(original)
+++ python/branches/py3k/Doc/tutorial/errors.rst	Tue May 13 06:55:24 2008
@@ -132,7 +132,7 @@
        s = f.readline()
        i = int(s.strip())
    except IOError as (errno, strerror):
-       print "I/O error(%s): %s" % (errno, strerror)
+       print("I/O error(%s): %s" % (errno, strerror))
    except ValueError:
        print("Could not convert data to an integer.")
    except:

Modified: python/branches/py3k/Lib/bsddb/dbrecio.py
==============================================================================
--- python/branches/py3k/Lib/bsddb/dbrecio.py	(original)
+++ python/branches/py3k/Lib/bsddb/dbrecio.py	Tue May 13 06:55:24 2008
@@ -158,14 +158,14 @@
     if f.getvalue() != text:
         raise RuntimeError, 'write failed'
     length = f.tell()
-    print 'File length =', length
+    print('File length =', length)
     f.seek(len(lines[0]))
     f.write(lines[1])
     f.seek(0)
-    print 'First line =', repr(f.readline())
+    print('First line =', repr(f.readline()))
     here = f.tell()
     line = f.readline()
-    print 'Second line =', repr(line)
+    print('Second line =', repr(line))
     f.seek(-len(line), 1)
     line2 = f.read(len(line))
     if line != line2:
@@ -177,8 +177,8 @@
     line2 = f.read()
     if line != line2:
         raise RuntimeError, 'bad result after seek back from EOF'
-    print 'Read', len(list), 'more lines'
-    print 'File length =', f.tell()
+    print('Read', len(list), 'more lines')
+    print('File length =', f.tell())
     if f.tell() != length:
         raise RuntimeError, 'bad length'
     f.close()

Modified: python/branches/py3k/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/py3k/Lib/idlelib/PyShell.py	(original)
+++ python/branches/py3k/Lib/idlelib/PyShell.py	Tue May 13 06:55:24 2008
@@ -1273,7 +1273,7 @@
         Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell
         window with the title "Baz".
 
-idle -c "import sys; print sys.argv" "foo"
+idle -c "import sys; print(sys.argv)" "foo"
         Open a shell window and run the command, passing "-c" in sys.argv[0]
         and "foo" in sys.argv[1].
 
@@ -1282,7 +1282,7 @@
         run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in
         sys.argv[1].
 
-echo "import sys; print sys.argv" | idle - "foobar"
+echo "import sys; print(sys.argv)" | idle - "foobar"
         Open a shell window, run the script piped in, passing '' in sys.argv[0]
         and "foobar" in sys.argv[1].
 """

Modified: python/branches/py3k/Lib/os.py
==============================================================================
--- python/branches/py3k/Lib/os.py	(original)
+++ python/branches/py3k/Lib/os.py	Tue May 13 06:55:24 2008
@@ -254,9 +254,9 @@
     import os
     from os.path import join, getsize
     for root, dirs, files in os.walk('python/Lib/email'):
-        print root, "consumes",
-        print sum([getsize(join(root, name)) for name in files]),
-        print "bytes in", len(files), "non-directory files"
+        print(root, "consumes", end="")
+        print(sum([getsize(join(root, name)) for name in files]), end="")
+        print("bytes in", len(files), "non-directory files")
         if 'CVS' in dirs:
             dirs.remove('CVS')  # don't visit CVS directories
     """

Modified: python/branches/py3k/Lib/pdb.py
==============================================================================
--- python/branches/py3k/Lib/pdb.py	(original)
+++ python/branches/py3k/Lib/pdb.py	Tue May 13 06:55:24 2008
@@ -500,7 +500,8 @@
         try:
             bp = bdb.Breakpoint.bpbynumber[bpnum]
         except IndexError:
-            print >>self.stdout, 'Breakpoint index %r is not valid' % args[0]
+            print('Breakpoint index %r is not valid' % args[0],
+                  file=self.stdout)
             return
         if bp:
             bp.cond = cond
@@ -524,7 +525,8 @@
         try:
             bp = bdb.Breakpoint.bpbynumber[bpnum]
         except IndexError:
-            print >>self.stdout, 'Breakpoint index %r is not valid' % args[0]
+            print('Breakpoint index %r is not valid' % args[0],
+                  file=self.stdout)
             return
         if bp:
             bp.ignore = count

Modified: python/branches/py3k/Lib/test/test_global.py
==============================================================================
--- python/branches/py3k/Lib/test/test_global.py	(original)
+++ python/branches/py3k/Lib/test/test_global.py	Tue May 13 06:55:24 2008
@@ -21,7 +21,7 @@
     def test2(self):
         prog_text_2 = """\
 def wrong2():
-    print x
+    print(x)
     global x
 """
         check_syntax_error(self, prog_text_2)
@@ -29,7 +29,7 @@
     def test3(self):
         prog_text_3 = """\
 def wrong3():
-    print x
+    print(x)
     x = 2
     global x
 """

Modified: python/branches/py3k/Lib/test/test_popen.py
==============================================================================
--- python/branches/py3k/Lib/test/test_popen.py	(original)
+++ python/branches/py3k/Lib/test/test_popen.py	Tue May 13 06:55:24 2008
@@ -10,7 +10,7 @@
 
 # Test that command-lines get down as we expect.
 # To do this we execute:
-#    python -c "import sys;print sys.argv" {rest_of_commandline}
+#    python -c "import sys;print(sys.argv)" {rest_of_commandline}
 # This results in Python being spawned and printing the sys.argv list.
 # We can then eval() the result of this, and see what each argv was.
 python = sys.executable

Modified: python/branches/py3k/Lib/test/test_support.py
==============================================================================
--- python/branches/py3k/Lib/test/test_support.py	(original)
+++ python/branches/py3k/Lib/test/test_support.py	Tue May 13 06:55:24 2008
@@ -481,7 +481,7 @@
     Example use (with 'stream_name=stdout')::
 
        with captured_stdout() as s:
-           print "hello"
+           print("hello")
        assert s.getvalue() == "hello"
     """
     import io

Modified: python/branches/py3k/Lib/test/test_tokenize.py
==============================================================================
--- python/branches/py3k/Lib/test/test_tokenize.py	(original)
+++ python/branches/py3k/Lib/test/test_tokenize.py	Tue May 13 06:55:24 2008
@@ -89,7 +89,7 @@
     >>> roundtrip("try: import somemodule\\n"
     ...           "except ImportError: # comment\\n"
     ...           "    print('Can not import' # comment2\\n)"
-    ...           "else:   print 'Loaded'\\n")
+    ...           "else:   print('Loaded')\\n")
     True
 
 Balancing continuation


More information about the Python-3000-checkins mailing list