Skip to content

Commit

Permalink
Fix most trivially-findable print statements.
Browse files Browse the repository at this point in the history
There's one major and one minor category still unfixed:
doctests are the major category (and I hope to be able to augment the
refactoring tool to refactor bona fide doctests soon);
other code generating print statements in strings is the minor category.

(Oh, and I don't know if the compiler package works.)
  • Loading branch information
gvanrossum committed Feb 9, 2007
1 parent 452bf51 commit be19ed7
Show file tree
Hide file tree
Showing 331 changed files with 2,568 additions and 2,649 deletions.
2 changes: 1 addition & 1 deletion Lib/BaseHTTPServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def test(HandlerClass = BaseHTTPRequestHandler,
httpd = ServerClass(server_address, HandlerClass)

sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
print("Serving HTTP on", sa[0], "port", sa[1], "...")
httpd.serve_forever()


Expand Down
2 changes: 1 addition & 1 deletion Lib/Bastion.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def total(self):
print "accessible"
\n"""
exec(testcode)
print '='*20, "Using rexec:", '='*20
print('='*20, "Using rexec:", '='*20)
import rexec
r = rexec.RExec()
m = r.add_module('__main__')
Expand Down
10 changes: 5 additions & 5 deletions Lib/Cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
>>> C = Cookie.SmartCookie()
>>> C["rocky"] = "road"
>>> C["rocky"]["path"] = "/cookie"
>>> print C.output(header="Cookie:")
>>> print(C.output(header="Cookie:"))
Cookie: rocky=road; Path=/cookie
>>> print C.output(attrs=[], header="Cookie:")
>>> print(C.output(attrs=[], header="Cookie:"))
Cookie: rocky=road
The load() method of a Cookie extracts cookies from a string. In a
Expand All @@ -100,7 +100,7 @@
>>> C = Cookie.SmartCookie()
>>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
>>> print C
>>> print(C)
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"
Each element of the Cookie also supports all of the RFC 2109
Expand All @@ -110,7 +110,7 @@
>>> C = Cookie.SmartCookie()
>>> C["oreo"] = "doublestuff"
>>> C["oreo"]["path"] = "/"
>>> print C
>>> print(C)
Set-Cookie: oreo=doublestuff; Path=/
Each dictionary element has a 'value' attribute, which gives you
Expand Down Expand Up @@ -198,7 +198,7 @@
fact, this simply returns a SmartCookie.
>>> C = Cookie.Cookie()
>>> print C.__class__.__name__
>>> print(C.__class__.__name__)
SmartCookie
Expand Down
6 changes: 3 additions & 3 deletions Lib/DocXMLRPCServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ def handle_get(self):

response = self.generate_html_documentation()

print 'Content-Type: text/html'
print 'Content-Length: %d' % len(response)
print
print('Content-Type: text/html')
print('Content-Length: %d' % len(response))
print()
sys.stdout.write(response)

def __init__(self):
Expand Down
16 changes: 8 additions & 8 deletions Lib/SimpleXMLRPCServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ def handle_xmlrpc(self, request_text):

response = self._marshaled_dispatch(request_text)

print 'Content-Type: text/xml'
print 'Content-Length: %d' % len(response)
print
print('Content-Type: text/xml')
print('Content-Length: %d' % len(response))
print()
sys.stdout.write(response)

def handle_get(self):
Expand All @@ -565,10 +565,10 @@ def handle_get(self):
'message' : message,
'explain' : explain
}
print 'Status: %d %s' % (code, message)
print 'Content-Type: text/html'
print 'Content-Length: %d' % len(response)
print
print('Status: %d %s' % (code, message))
print('Content-Type: text/html')
print('Content-Length: %d' % len(response))
print()
sys.stdout.write(response)

def handle_request(self, request_text = None):
Expand All @@ -590,7 +590,7 @@ def handle_request(self, request_text = None):
self.handle_xmlrpc(request_text)

if __name__ == '__main__':
print 'Running XML-RPC server on port 8000'
print('Running XML-RPC server on port 8000')
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
Expand Down
8 changes: 4 additions & 4 deletions Lib/SocketServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ def handle_error(self, request, client_address):
The default is to print a traceback and continue.
"""
print '-'*40
print 'Exception happened during processing of request from',
print client_address
print('-'*40)
print('Exception happened during processing of request from', end=' ')
print(client_address)
import traceback
traceback.print_exc() # XXX But this goes to stderr!
print '-'*40
print('-'*40)


class TCPServer(BaseServer):
Expand Down
14 changes: 7 additions & 7 deletions Lib/StringIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,14 @@ def test():
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 'Position =', f.tell()
print('First line =', repr(f.readline()))
print('Position =', 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:
Expand All @@ -310,13 +310,13 @@ def test():
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.truncate(length/2)
f.seek(0, 2)
print 'Truncated length =', f.tell()
print('Truncated length =', f.tell())
if f.tell() != length/2:
raise RuntimeError, 'truncate did not adjust length'
f.close()
Expand Down
30 changes: 15 additions & 15 deletions Lib/aifc.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def _read_comm_chunk(self, chunk):
kludge = 0
if chunk.chunksize == 18:
kludge = 1
print 'Warning: bad COMM chunk size'
print('Warning: bad COMM chunk size')
chunk.chunksize = 23
#DEBUG end
self._comptype = chunk.read(4)
Expand Down Expand Up @@ -518,11 +518,11 @@ def _readmark(self, chunk):
# a position 0 and name ''
self._markers.append((id, pos, name))
except EOFError:
print 'Warning: MARK chunk contains only',
print len(self._markers),
if len(self._markers) == 1: print 'marker',
else: print 'markers',
print 'instead of', nmarkers
print('Warning: MARK chunk contains only', end=' ')
print(len(self._markers), end=' ')
if len(self._markers) == 1: print('marker', end=' ')
else: print('markers', end=' ')
print('instead of', nmarkers)

class Aifc_write:
# Variables used in this class:
Expand Down Expand Up @@ -939,16 +939,16 @@ def open(f, mode=None):
sys.argv.append('/usr/demos/data/audio/bach.aiff')
fn = sys.argv[1]
f = open(fn, 'r')
print "Reading", fn
print "nchannels =", f.getnchannels()
print "nframes =", f.getnframes()
print "sampwidth =", f.getsampwidth()
print "framerate =", f.getframerate()
print "comptype =", f.getcomptype()
print "compname =", f.getcompname()
print("Reading", fn)
print("nchannels =", f.getnchannels())
print("nframes =", f.getnframes())
print("sampwidth =", f.getsampwidth())
print("framerate =", f.getframerate())
print("comptype =", f.getcomptype())
print("compname =", f.getcompname())
if sys.argv[2:]:
gn = sys.argv[2]
print "Writing", gn
print("Writing", gn)
g = open(gn, 'w')
g.setparams(f.getparams())
while 1:
Expand All @@ -958,4 +958,4 @@ def open(f, mode=None):
g.writeframes(data)
g.close()
f.close()
print "Done."
print("Done.")
2 changes: 1 addition & 1 deletion Lib/asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def log(self, message):

def log_info(self, message, type='info'):
if __debug__ or type != 'info':
print '%s: %s' % (type, message)
print('%s: %s' % (type, message))

def handle_read_event(self):
if self.accepting:
Expand Down
8 changes: 4 additions & 4 deletions Lib/atexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _run_exitfuncs():
exc_info = sys.exc_info()
except:
import traceback
print >> sys.stderr, "Error in atexit._run_exitfuncs:"
print("Error in atexit._run_exitfuncs:", file=sys.stderr)
traceback.print_exc()
exc_info = sys.exc_info()

Expand All @@ -53,11 +53,11 @@ def register(func, *targs, **kargs):

if __name__ == "__main__":
def x1():
print "running x1"
print("running x1")
def x2(n):
print "running x2(%r)" % (n,)
print("running x2(%r)" % (n,))
def x3(n, kwd=None):
print "running x3(%r, kwd=%r)" % (n, kwd)
print("running x3(%r, kwd=%r)" % (n, kwd))

register(x1)
register(x2, 12)
Expand Down
4 changes: 2 additions & 2 deletions Lib/audiodev.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test(fn = None):
fn = 'f:just samples:just.aif'
import aifc
af = aifc.open(fn, 'r')
print fn, af.getparams()
print(fn, af.getparams())
p = AudioDev()
p.setoutrate(af.getframerate())
p.setsampwidth(af.getsampwidth())
Expand All @@ -249,7 +249,7 @@ def test(fn = None):
while 1:
data = af.readframes(BUFSIZ)
if not data: break
print len(data)
print(len(data))
p.writeframes(data)
p.wait()

Expand Down
8 changes: 4 additions & 4 deletions Lib/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ def test():
opts, args = getopt.getopt(sys.argv[1:], 'deut')
except getopt.error as msg:
sys.stdout = sys.stderr
print msg
print """usage: %s [-d|-e|-u|-t] [file|-]
print(msg)
print("""usage: %s [-d|-e|-u|-t] [file|-]
-d, -u: decode
-e: encode (default)
-t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0]
-t: encode and decode string 'Aladdin:open sesame'"""%sys.argv[0])
sys.exit(2)
func = encode
for o, a in opts:
Expand All @@ -352,7 +352,7 @@ def test1():
s0 = "Aladdin:open sesame"
s1 = encodestring(s0)
s2 = decodestring(s1)
print s0, repr(s1), s2
print(s0, repr(s1), s2)


if __name__ == '__main__':
Expand Down
28 changes: 14 additions & 14 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def trace_dispatch(self, frame, event, arg):
return self.trace_dispatch
if event == 'c_return':
return self.trace_dispatch
print 'bdb.Bdb.dispatch: unknown debugging event:', repr(event)
print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
return self.trace_dispatch

def dispatch_line(self, frame):
Expand Down Expand Up @@ -483,17 +483,17 @@ def bpprint(self, out=None):
disp = disp + 'yes '
else:
disp = disp + 'no '
print >>out, '%-4dbreakpoint %s at %s:%d' % (self.number, disp,
self.file, self.line)
print('%-4dbreakpoint %s at %s:%d' % (self.number, disp,
self.file, self.line), file=out)
if self.cond:
print >>out, '\tstop only if %s' % (self.cond,)
print('\tstop only if %s' % (self.cond,), file=out)
if self.ignore:
print >>out, '\tignore next %d hits' % (self.ignore)
print('\tignore next %d hits' % (self.ignore), file=out)
if (self.hits):
if (self.hits > 1): ss = 's'
else: ss = ''
print >>out, ('\tbreakpoint already hit %d time%s' %
(self.hits, ss))
print(('\tbreakpoint already hit %d time%s' %
(self.hits, ss)), file=out)

# -----------end of Breakpoint class----------

Expand Down Expand Up @@ -582,27 +582,27 @@ class Tdb(Bdb):
def user_call(self, frame, args):
name = frame.f_code.co_name
if not name: name = '???'
print '+++ call', name, args
print('+++ call', name, args)
def user_line(self, frame):
import linecache
name = frame.f_code.co_name
if not name: name = '???'
fn = self.canonic(frame.f_code.co_filename)
line = linecache.getline(fn, frame.f_lineno)
print '+++', fn, frame.f_lineno, name, ':', line.strip()
print('+++', fn, frame.f_lineno, name, ':', line.strip())
def user_return(self, frame, retval):
print '+++ return', retval
print('+++ return', retval)
def user_exception(self, frame, exc_stuff):
print '+++ exception', exc_stuff
print('+++ exception', exc_stuff)
self.set_continue()

def foo(n):
print 'foo(', n, ')'
print('foo(', n, ')')
x = bar(n*10)
print 'bar returned', x
print('bar returned', x)

def bar(a):
print 'bar(', a, ')'
print('bar(', a, ')')
return a/2

def test():
Expand Down
4 changes: 2 additions & 2 deletions Lib/bsddb/dbtables.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ def sync(self):

def _db_print(self) :
"""Print the database to stdout for debugging"""
print "******** Printing raw database for debugging ********"
print("******** Printing raw database for debugging ********")
cur = self.db.cursor()
try:
key, data = cur.first()
while 1:
print repr({key: data})
print(repr({key: data}))
next = cur.next()
if next:
key, data = next
Expand Down
18 changes: 9 additions & 9 deletions Lib/bsddb/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@


def print_versions():
print
print '-=' * 38
print db.DB_VERSION_STRING
print 'bsddb.db.version(): %s' % (db.version(), )
print 'bsddb.db.__version__: %s' % db.__version__
print 'bsddb.db.cvsid: %s' % db.cvsid
print 'python version: %s' % sys.version
print 'My pid: %s' % os.getpid()
print '-=' * 38
print()
print('-=' * 38)
print(db.DB_VERSION_STRING)
print('bsddb.db.version(): %s' % (db.version(), ))
print('bsddb.db.__version__: %s' % db.__version__)
print('bsddb.db.cvsid: %s' % db.cvsid)
print('python version: %s' % sys.version)
print('My pid: %s' % os.getpid())
print('-=' * 38)


class PrintInfoFakeTest(unittest.TestCase):
Expand Down
Loading

1 comment on commit be19ed7

@TheRedstoneRadiant
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python2 moment

Please sign in to comment.