summaryrefslogtreecommitdiffstats
path: root/Demo/scripts
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2007-07-17 20:59:35 (GMT)
committerCollin Winter <collinw@gmail.com>2007-07-17 20:59:35 (GMT)
commit6f2df4d5e193d54244b0c2de91ef0ab1604b9243 (patch)
tree5e172400da7561eb4bb8fafc62c8cab511d74dad /Demo/scripts
parenta8c360ee76fb76902a2e2140fbb38d4b06b2d9fb (diff)
downloadcpython-6f2df4d5e193d54244b0c2de91ef0ab1604b9243.zip
cpython-6f2df4d5e193d54244b0c2de91ef0ab1604b9243.tar.gz
cpython-6f2df4d5e193d54244b0c2de91ef0ab1604b9243.tar.bz2
Run 2to3 over the Demo/ directory to shut up parse errors from 2to3 about lingering print statements.
Diffstat (limited to 'Demo/scripts')
-rw-r--r--Demo/scripts/beer.py8
-rwxr-xr-xDemo/scripts/eqfix.py12
-rwxr-xr-xDemo/scripts/fact.py6
-rw-r--r--Demo/scripts/find-uname.py6
-rwxr-xr-xDemo/scripts/from.py6
-rwxr-xr-xDemo/scripts/ftpstats.py24
-rwxr-xr-xDemo/scripts/lpwatch.py8
-rwxr-xr-xDemo/scripts/makedir.py2
-rwxr-xr-xDemo/scripts/markov.py56
-rwxr-xr-xDemo/scripts/mboxconvert.py14
-rwxr-xr-xDemo/scripts/mkrcs.py16
-rwxr-xr-xDemo/scripts/newslist.py72
-rwxr-xr-xDemo/scripts/pi.py6
-rwxr-xr-xDemo/scripts/pp.py2
-rwxr-xr-xDemo/scripts/primes.py4
-rwxr-xr-xDemo/scripts/queens.py14
-rwxr-xr-xDemo/scripts/script.py2
-rwxr-xr-xDemo/scripts/unbirthday.py42
-rwxr-xr-xDemo/scripts/update.py34
19 files changed, 168 insertions, 166 deletions
diff --git a/Demo/scripts/beer.py b/Demo/scripts/beer.py
index 1b9ac8b..f050572 100644
--- a/Demo/scripts/beer.py
+++ b/Demo/scripts/beer.py
@@ -8,7 +8,7 @@ def bottle(n):
if n == 1: return "one bottle of beer"
return str(n) + " bottles of beer"
for i in range(n):
- print bottle(n-i), "on the wall,"
- print bottle(n-i) + "."
- print "Take one down, pass it around,"
- print bottle(n-i-1), "on the wall."
+ print(bottle(n-i), "on the wall,")
+ print(bottle(n-i) + ".")
+ print("Take one down, pass it around,")
+ print(bottle(n-i-1), "on the wall.")
diff --git a/Demo/scripts/eqfix.py b/Demo/scripts/eqfix.py
index 497ab20..47c00d3 100755
--- a/Demo/scripts/eqfix.py
+++ b/Demo/scripts/eqfix.py
@@ -143,7 +143,7 @@ def fix(filename):
# First copy the file's mode to the temp file
try:
statbuf = os.stat(filename)
- os.chmod(tempname, statbuf[ST_MODE] & 07777)
+ os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
except os.error as msg:
err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
# Then make a backup of the original file as filename~
@@ -176,22 +176,22 @@ def fixline(line):
j = tokenprog.match(line, i)
if j < 0:
# A bad token; forget about the rest of this line
- print '(Syntax error:)'
- print line,
+ print('(Syntax error:)')
+ print(line, end=' ')
return line
a, b = tokenprog.regs[3] # Location of the token proper
token = line[a:b]
i = i+j
if stack and token == stack[-1]:
del stack[-1]
- elif match.has_key(token):
+ elif token in match:
stack.append(match[token])
elif token == '=' and stack:
line = line[:a] + '==' + line[b:]
i, n = a + len('=='), len(line)
elif token == '==' and not stack:
- print '(Warning: \'==\' at top level:)'
- print line,
+ print('(Warning: \'==\' at top level:)')
+ print(line, end=' ')
return line
if __name__ == "__main__":
diff --git a/Demo/scripts/fact.py b/Demo/scripts/fact.py
index 03cab8b..19d28eb 100755
--- a/Demo/scripts/fact.py
+++ b/Demo/scripts/fact.py
@@ -36,12 +36,12 @@ def main():
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
n = eval(arg)
- print n, fact(n)
+ print(n, fact(n))
else:
try:
while 1:
- n = input()
- print n, fact(n)
+ n = eval(input())
+ print(n, fact(n))
except EOFError:
pass
diff --git a/Demo/scripts/find-uname.py b/Demo/scripts/find-uname.py
index b76b9f0..fbf4033 100644
--- a/Demo/scripts/find-uname.py
+++ b/Demo/scripts/find-uname.py
@@ -24,7 +24,7 @@ def main(args):
unicode_names= []
for ix in range(sys.maxunicode+1):
try:
- unicode_names.append( (ix, unicodedata.name(unichr(ix))) )
+ unicode_names.append( (ix, unicodedata.name(chr(ix))) )
except ValueError: # no name for the character
pass
for arg in args:
@@ -32,9 +32,9 @@ def main(args):
matches = [(x,y) for (x,y) in unicode_names
if pat.search(y) is not None]
if matches:
- print "***", arg, "matches", "***"
+ print("***", arg, "matches", "***")
for (x,y) in matches:
- print "%s (%d)" % (y,x)
+ print("%s (%d)" % (y,x))
if __name__ == "__main__":
main(sys.argv[1:])
diff --git a/Demo/scripts/from.py b/Demo/scripts/from.py
index 3c04fcd..323e684 100755
--- a/Demo/scripts/from.py
+++ b/Demo/scripts/from.py
@@ -25,11 +25,11 @@ while 1:
break # EOF
if line.startswith('From '):
# Start of message found
- print line[:-1],
+ print(line[:-1], end=' ')
while 1:
line = mail.readline()
if not line or line == '\n':
break
if line.startswith('Subject: '):
- print repr(line[9:-1]),
- print
+ print(repr(line[9:-1]), end=' ')
+ print()
diff --git a/Demo/scripts/ftpstats.py b/Demo/scripts/ftpstats.py
index c7c0749..d0a0824 100755
--- a/Demo/scripts/ftpstats.py
+++ b/Demo/scripts/ftpstats.py
@@ -26,8 +26,8 @@ def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'm:s:')
except getopt.error as msg:
- print msg
- print 'usage: ftpstats [-m maxitems] [file]'
+ print(msg)
+ print('usage: ftpstats [-m maxitems] [file]')
sys.exit(2)
for o, a in opts:
if o == '-m':
@@ -42,7 +42,7 @@ def main():
try:
f = open(file, 'r')
except IOError as msg:
- print file, ':', msg
+ print(file, ':', msg)
sys.exit(1)
bydate = {}
bytime = {}
@@ -60,7 +60,7 @@ def main():
if search and string.find(line, search) < 0:
continue
if prog.match(line) < 0:
- print 'Bad line', lineno, ':', repr(line)
+ print('Bad line', lineno, ':', repr(line))
continue
items = prog.group(1, 2, 3, 4, 5, 6)
(logtime, loguser, loghost, logfile, logbytes,
@@ -93,7 +93,7 @@ def main():
add(byuser, loguser, items)
add(bytype, direction, items)
except KeyboardInterrupt:
- print 'Interrupted at line', lineno
+ print('Interrupted at line', lineno)
show(bytype, 'by transfer direction', maxitems)
show(bydir, 'by directory', maxitems)
show(byfile, 'by file', maxitems)
@@ -104,9 +104,9 @@ def main():
def showbar(dict, title):
n = len(title)
- print '='*((70-n)/2), title, '='*((71-n)/2)
+ print('='*((70-n)/2), title, '='*((71-n)/2))
list = []
- keys = dict.keys()
+ keys = list(dict.keys())
keys.sort()
for key in keys:
n = len(str(key))
@@ -120,23 +120,23 @@ def showbar(dict, title):
for count, key in list:
barlength = int(round(maxbarlength*float(count)/maxcount))
bar = '*'*barlength
- print '%5d %-*s %s' % (count, maxkeylength, key, bar)
+ print('%5d %-*s %s' % (count, maxkeylength, key, bar))
def show(dict, title, maxitems):
if len(dict) > maxitems:
title = title + ' (first %d)'%maxitems
n = len(title)
- print '='*((70-n)/2), title, '='*((71-n)/2)
+ print('='*((70-n)/2), title, '='*((71-n)/2))
list = []
- keys = dict.keys()
+ keys = list(dict.keys())
for key in keys:
list.append((-len(dict[key]), key))
list.sort()
for count, key in list[:maxitems]:
- print '%5d %s' % (-count, key)
+ print('%5d %s' % (-count, key))
def add(dict, key, item):
- if dict.has_key(key):
+ if key in dict:
dict[key].append(item)
else:
dict[key] = [item]
diff --git a/Demo/scripts/lpwatch.py b/Demo/scripts/lpwatch.py
index c3dcb34..567385c 100755
--- a/Demo/scripts/lpwatch.py
+++ b/Demo/scripts/lpwatch.py
@@ -25,7 +25,7 @@ def main():
if printers[i][:2] == '-P':
printers[i] = printers[i][2:]
else:
- if posix.environ.has_key('PRINTER'):
+ if 'PRINTER' in posix.environ:
printers = [posix.environ['PRINTER']]
else:
printers = [DEF_PRINTER]
@@ -36,7 +36,7 @@ def main():
text = clearhome
for name in printers:
text = text + makestatus(name, thisuser) + '\n'
- print text
+ print(text)
time.sleep(delay)
def makestatus(name, thisuser):
@@ -66,7 +66,7 @@ def makestatus(name, thisuser):
aheadjobs = aheadjobs + 1
totalbytes = totalbytes + bytes
totaljobs = totaljobs + 1
- if users.has_key(user):
+ if user in users:
ujobs, ubytes = users[user]
else:
ujobs, ubytes = 0, 0
@@ -87,7 +87,7 @@ def makestatus(name, thisuser):
if totaljobs != len(users):
line = line + ' (%d jobs)' % totaljobs
if len(users) == 1:
- line = line + ' for %s' % (users.keys()[0],)
+ line = line + ' for %s' % (list(users.keys())[0],)
else:
line = line + ' for %d users' % len(users)
if userseen:
diff --git a/Demo/scripts/makedir.py b/Demo/scripts/makedir.py
index f70facd..7095868 100755
--- a/Demo/scripts/makedir.py
+++ b/Demo/scripts/makedir.py
@@ -15,7 +15,7 @@ def makedirs(p):
if p and not os.path.isdir(p):
head, tail = os.path.split(p)
makedirs(head)
- os.mkdir(p, 0777)
+ os.mkdir(p, 0o777)
if __name__ == "__main__":
main()
diff --git a/Demo/scripts/markov.py b/Demo/scripts/markov.py
index bddec56..a91e359 100755
--- a/Demo/scripts/markov.py
+++ b/Demo/scripts/markov.py
@@ -6,7 +6,7 @@ class Markov:
self.choice = choice
self.trans = {}
def add(self, state, next):
- if not self.trans.has_key(state):
+ if state not in self.trans:
self.trans[state] = [next]
else:
self.trans[state].append(next)
@@ -36,19 +36,19 @@ def test():
try:
opts, args = getopt.getopt(args, '0123456789cdw')
except getopt.error:
- print 'Usage: markov [-#] [-cddqw] [file] ...'
- print 'Options:'
- print '-#: 1-digit history size (default 2)'
- print '-c: characters (default)'
- print '-w: words'
- print '-d: more debugging output'
- print '-q: no debugging output'
- print 'Input files (default stdin) are split in paragraphs'
- print 'separated blank lines and each paragraph is split'
- print 'in words by whitespace, then reconcatenated with'
- print 'exactly one space separating words.'
- print 'Output consists of paragraphs separated by blank'
- print 'lines, where lines are no longer than 72 characters.'
+ print('Usage: markov [-#] [-cddqw] [file] ...')
+ print('Options:')
+ print('-#: 1-digit history size (default 2)')
+ print('-c: characters (default)')
+ print('-w: words')
+ print('-d: more debugging output')
+ print('-q: no debugging output')
+ print('Input files (default stdin) are split in paragraphs')
+ print('separated blank lines and each paragraph is split')
+ print('in words by whitespace, then reconcatenated with')
+ print('exactly one space separating words.')
+ print('Output consists of paragraphs separated by blank')
+ print('lines, where lines are no longer than 72 characters.')
histsize = 2
do_words = 0
debug = 1
@@ -65,33 +65,33 @@ def test():
if filename == '-':
f = sys.stdin
if f.isatty():
- print 'Sorry, need stdin from file'
+ print('Sorry, need stdin from file')
continue
else:
f = open(filename, 'r')
- if debug: print 'processing', filename, '...'
+ if debug: print('processing', filename, '...')
text = f.read()
f.close()
paralist = string.splitfields(text, '\n\n')
for para in paralist:
- if debug > 1: print 'feeding ...'
+ if debug > 1: print('feeding ...')
words = string.split(para)
if words:
if do_words: data = tuple(words)
else: data = string.joinfields(words, ' ')
m.put(data)
except KeyboardInterrupt:
- print 'Interrupted -- continue with data read so far'
+ print('Interrupted -- continue with data read so far')
if not m.trans:
- print 'No valid input files'
+ print('No valid input files')
return
- if debug: print 'done.'
+ if debug: print('done.')
if debug > 1:
- for key in m.trans.keys():
+ for key in list(m.trans.keys()):
if key is None or len(key) < histsize:
- print repr(key), m.trans[key]
- if histsize == 0: print repr(''), m.trans['']
- print
+ print(repr(key), m.trans[key])
+ if histsize == 0: print(repr(''), m.trans[''])
+ print()
while 1:
data = m.get()
if do_words: words = data
@@ -100,12 +100,12 @@ def test():
limit = 72
for w in words:
if n + len(w) > limit:
- print
+ print()
n = 0
- print w,
+ print(w, end=' ')
n = n + len(w) + 1
- print
- print
+ print()
+ print()
def tuple(list):
if len(list) == 0: return ()
diff --git a/Demo/scripts/mboxconvert.py b/Demo/scripts/mboxconvert.py
index 8da37bf..787c760 100755
--- a/Demo/scripts/mboxconvert.py
+++ b/Demo/scripts/mboxconvert.py
@@ -91,19 +91,19 @@ def message(f, delimiter = ''):
sys.stderr.write(
'Unparseable date: %r\n' % (m.getheader('Date'),))
t = os.fstat(f.fileno())[stat.ST_MTIME]
- print 'From', email, time.ctime(t)
+ print('From', email, time.ctime(t))
# Copy RFC822 header
for line in m.headers:
- print line,
+ print(line, end=' ')
# Invent Message-ID header if none is present
- if not m.has_key('message-id'):
+ if 'message-id' not in m:
global counter
counter = counter + 1
msgid = "<%s.%d>" % (hex(t), counter)
sys.stderr.write("Adding Message-ID %s (From %s)\n" %
(msgid, email))
- print "Message-ID:", msgid
- print
+ print("Message-ID:", msgid)
+ print()
# Copy body
while 1:
line = f.readline()
@@ -115,9 +115,9 @@ def message(f, delimiter = ''):
break
if line[:5] == 'From ':
line = '>' + line
- print line,
+ print(line, end=' ')
# Print trailing newline
- print
+ print()
return sts
if __name__ == "__main__":
diff --git a/Demo/scripts/mkrcs.py b/Demo/scripts/mkrcs.py
index cacdda0..317647a 100755
--- a/Demo/scripts/mkrcs.py
+++ b/Demo/scripts/mkrcs.py
@@ -12,13 +12,13 @@ def main():
rcstree = 'RCStree'
rcs = 'RCS'
if os.path.islink(rcs):
- print '%r is a symlink to %r' % (rcs, os.readlink(rcs))
+ print('%r is a symlink to %r' % (rcs, os.readlink(rcs)))
return
if os.path.isdir(rcs):
- print '%r is an ordinary directory' % (rcs,)
+ print('%r is an ordinary directory' % (rcs,))
return
if os.path.exists(rcs):
- print '%r is a file?!?!' % (rcs,)
+ print('%r is a file?!?!' % (rcs,))
return
#
p = os.getcwd()
@@ -34,7 +34,7 @@ def main():
head, tail = os.path.split(p)
#print 'head = %r; tail = %r' % (head, tail)
if not tail:
- print 'Sorry, no ancestor dir contains %r' % (rcstree,)
+ print('Sorry, no ancestor dir contains %r' % (rcstree,))
return
p = head
up = os.path.join(os.pardir, up)
@@ -44,18 +44,18 @@ def main():
there = os.path.join(there, down)
there = os.path.join(there, rcs)
if os.path.isdir(there):
- print '%r already exists' % (there, )
+ print('%r already exists' % (there, ))
else:
- print 'making %r' % (there,)
+ print('making %r' % (there,))
makedirs(there)
- print 'making symlink %r -> %r' % (rcs, there)
+ print('making symlink %r -> %r' % (rcs, there))
os.symlink(there, rcs)
def makedirs(p):
if not os.path.isdir(p):
head, tail = os.path.split(p)
makedirs(head)
- os.mkdir(p, 0777)
+ os.mkdir(p, 0o777)
if __name__ == "__main__":
main()
diff --git a/Demo/scripts/newslist.py b/Demo/scripts/newslist.py
index 0111ace..4635f1d 100755
--- a/Demo/scripts/newslist.py
+++ b/Demo/scripts/newslist.py
@@ -98,7 +98,7 @@ sublistsize = 4
for dir in os.curdir, os.environ['HOME']:
rcfile = os.path.join(dir, '.newslistrc.py')
if os.path.exists(rcfile):
- print rcfile
+ print(rcfile)
execfile(rcfile)
break
@@ -106,7 +106,7 @@ from nntplib import NNTP
from stat import *
rcsrev = '$Revision$'
-rcsrev = string.join(filter(lambda s: '$' not in s, string.split(rcsrev)))
+rcsrev = string.join([s for s in string.split(rcsrev) if '$' not in s])
desc = {}
# Make (possibly) relative filenames into absolute ones
@@ -118,7 +118,7 @@ page = os.path.join(topdir,pagedir)
# Addtotree creates/augments a tree from a list of group names
def addtotree(tree, groups):
- print 'Updating tree...'
+ print('Updating tree...')
for i in groups:
parts = string.splitfields(i,'.')
makeleaf(tree, parts)
@@ -128,7 +128,7 @@ def makeleaf(tree,path):
j = path[0]
l = len(path)
- if not tree.has_key(j):
+ if j not in tree:
tree[j] = {}
if l == 1:
tree[j]['.'] = '.'
@@ -172,7 +172,7 @@ def printtree(f, tree, indent, p):
createpage(p[1:], tree, p)
return
- kl = tree.keys()
+ kl = list(tree.keys())
if l > 1:
kl.sort()
@@ -188,7 +188,7 @@ def printtree(f, tree, indent, p):
if i == '.':
# Output a newsgroup
f.write('<LI><A HREF="news:' + p[1:] + '">'+ p[1:] + '</A> ')
- if desc.has_key(p[1:]):
+ if p[1:] in desc:
f.write(' <I>'+desc[p[1:]]+'</I>\n')
else:
f.write('\n')
@@ -213,9 +213,9 @@ def readdesc(descfile):
try:
d = open(descfile, 'r')
- print 'Reading descriptions...'
+ print('Reading descriptions...')
except (IOError):
- print 'Failed to open description file ' + descfile
+ print('Failed to open description file ' + descfile)
return
l = d.readline()
while l != '':
@@ -234,29 +234,29 @@ def readdesc(descfile):
def checkopdir(pagedir):
if not os.path.isdir(pagedir):
- print 'Directory '+pagedir+' does not exist.'
- print 'Shall I create it for you? (y/n)'
+ print('Directory '+pagedir+' does not exist.')
+ print('Shall I create it for you? (y/n)')
if sys.stdin.readline()[0] == 'y':
try:
- os.mkdir(pagedir,0777)
+ os.mkdir(pagedir,0o777)
except:
- print 'Sorry - failed!'
+ print('Sorry - failed!')
sys.exit(1)
else:
- print 'OK. Exiting.'
+ print('OK. Exiting.')
sys.exit(1)
# Read and write current local tree ----------------------------------
def readlocallist(treefile):
- print 'Reading current local group list...'
+ print('Reading current local group list...')
tree = {}
try:
treetime = time.localtime(os.stat(treefile)[ST_MTIME])
except:
- print '\n*** Failed to open local group cache '+treefile
- print 'If this is the first time you have run newslist, then'
- print 'use the -a option to create it.'
+ print('\n*** Failed to open local group cache '+treefile)
+ print('If this is the first time you have run newslist, then')
+ print('use the -a option to create it.')
sys.exit(1)
treedate = '%02d%02d%02d' % (treetime[0] % 100 ,treetime[1], treetime[2])
try:
@@ -264,7 +264,7 @@ def readlocallist(treefile):
tree = marshal.load(dump)
dump.close()
except (IOError):
- print 'Cannot open local group list ' + treefile
+ print('Cannot open local group list ' + treefile)
return (tree, treedate)
def writelocallist(treefile, tree):
@@ -272,45 +272,45 @@ def writelocallist(treefile, tree):
dump = open(treefile,'w')
groups = marshal.dump(tree,dump)
dump.close()
- print 'Saved list to '+treefile+'\n'
+ print('Saved list to '+treefile+'\n')
except:
- print 'Sorry - failed to write to local group cache '+treefile
- print 'Does it (or its directory) have the correct permissions?'
+ print('Sorry - failed to write to local group cache '+treefile)
+ print('Does it (or its directory) have the correct permissions?')
sys.exit(1)
# Return list of all groups on server -----------------------------
def getallgroups(server):
- print 'Getting list of all groups...'
+ print('Getting list of all groups...')
treedate='010101'
info = server.list()[1]
groups = []
- print 'Processing...'
+ print('Processing...')
if skipempty:
- print '\nIgnoring following empty groups:'
+ print('\nIgnoring following empty groups:')
for i in info:
grpname = string.split(i[0])[0]
if skipempty and string.atoi(i[1]) < string.atoi(i[2]):
- print grpname+' ',
+ print(grpname+' ', end=' ')
else:
groups.append(grpname)
- print '\n'
+ print('\n')
if skipempty:
- print '(End of empty groups)'
+ print('(End of empty groups)')
return groups
# Return list of new groups on server -----------------------------
def getnewgroups(server, treedate):
- print 'Getting list of new groups since start of '+treedate+'...',
+ print('Getting list of new groups since start of '+treedate+'...', end=' ')
info = server.newgroups(treedate,'000001')[1]
- print 'got %d.' % len(info)
- print 'Processing...',
+ print('got %d.' % len(info))
+ print('Processing...', end=' ')
groups = []
for i in info:
grpname = string.split(i)[0]
groups.append(grpname)
- print 'Done'
+ print('Done')
return groups
# Now the main program --------------------------------------------
@@ -324,15 +324,15 @@ def main():
checkopdir(pagedir);
try:
- print 'Connecting to '+newshost+'...'
+ print('Connecting to '+newshost+'...')
if sys.version[0] == '0':
s = NNTP.init(newshost)
else:
s = NNTP(newshost)
connected = 1
except (nntplib.error_temp, nntplib.error_perm) as x:
- print 'Error connecting to host:', x
- print 'I\'ll try to use just the local list.'
+ print('Error connecting to host:', x)
+ print('I\'ll try to use just the local list.')
connected = 0
# If -a is specified, read the full list of groups from server
@@ -355,9 +355,9 @@ def main():
# Read group descriptions
readdesc(descfile)
- print 'Creating pages...'
+ print('Creating pages...')
createpage(rootpage, tree, '')
- print 'Done'
+ print('Done')
if __name__ == "__main__":
main()
diff --git a/Demo/scripts/pi.py b/Demo/scripts/pi.py
index 9b24245..a360e40 100755
--- a/Demo/scripts/pi.py
+++ b/Demo/scripts/pi.py
@@ -11,16 +11,16 @@
import sys
def main():
- k, a, b, a1, b1 = 2L, 4L, 1L, 12L, 4L
+ k, a, b, a1, b1 = 2, 4, 1, 12, 4
while 1:
# Next approximation
- p, q, k = k*k, 2L*k+1L, k+1L
+ p, q, k = k*k, 2*k+1, k+1
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
# Print common digits
d, d1 = a/b, a1/b1
while d == d1:
output(d)
- a, a1 = 10L*(a%b), 10L*(a1%b1)
+ a, a1 = 10*(a%b), 10*(a1%b1)
d, d1 = a/b, a1/b1
def output(d):
diff --git a/Demo/scripts/pp.py b/Demo/scripts/pp.py
index 2530ea3..486986a 100755
--- a/Demo/scripts/pp.py
+++ b/Demo/scripts/pp.py
@@ -58,7 +58,7 @@ for option, optarg in optlist:
NFLAG = 1
PFLAG = 1
else:
- print option, 'not recognized???'
+ print(option, 'not recognized???')
if not ARGS: ARGS.append('-')
diff --git a/Demo/scripts/primes.py b/Demo/scripts/primes.py
index 8762fe2..0924aab 100755
--- a/Demo/scripts/primes.py
+++ b/Demo/scripts/primes.py
@@ -12,7 +12,7 @@ def main():
primes(min, max)
def primes(min, max):
- if 2 >= min: print 2
+ if 2 >= min: print(2)
primes = [2]
i = 3
while i <= max:
@@ -20,7 +20,7 @@ def primes(min, max):
if i%p == 0 or p*p > i: break
if i%p != 0:
primes.append(i)
- if i >= min: print i
+ if i >= min: print(i)
i = i+2
if __name__ == "__main__":
diff --git a/Demo/scripts/queens.py b/Demo/scripts/queens.py
index 74756be..820c9ad 100755
--- a/Demo/scripts/queens.py
+++ b/Demo/scripts/queens.py
@@ -56,16 +56,16 @@ class Queens:
self.nfound = self.nfound + 1
if self.silent:
return
- print '+-' + '--'*self.n + '+'
+ print('+-' + '--'*self.n + '+')
for y in range(self.n-1, -1, -1):
- print '|',
+ print('|', end=' ')
for x in range(self.n):
if self.y[x] == y:
- print "Q",
+ print("Q", end=' ')
else:
- print ".",
- print '|'
- print '+-' + '--'*self.n + '+'
+ print(".", end=' ')
+ print('|')
+ print('+-' + '--'*self.n + '+')
def main():
import sys
@@ -79,7 +79,7 @@ def main():
q = Queens(n)
q.silent = silent
q.solve()
- print "Found", q.nfound, "solutions."
+ print("Found", q.nfound, "solutions.")
if __name__ == "__main__":
main()
diff --git a/Demo/scripts/script.py b/Demo/scripts/script.py
index 6eaa7ae..174c13e 100755
--- a/Demo/scripts/script.py
+++ b/Demo/scripts/script.py
@@ -17,7 +17,7 @@ def read(fd):
shell = 'sh'
filename = 'typescript'
mode = 'w'
-if os.environ.has_key('SHELL'):
+if 'SHELL' in os.environ:
shell = os.environ['SHELL']
if '-a' in sys.argv:
mode = 'a'
diff --git a/Demo/scripts/unbirthday.py b/Demo/scripts/unbirthday.py
index 94ad448..5c39092 100755
--- a/Demo/scripts/unbirthday.py
+++ b/Demo/scripts/unbirthday.py
@@ -21,69 +21,70 @@ def main():
if sys.argv[1:]:
year = int(sys.argv[1])
else:
- year = int(raw_input('In which year were you born? '))
+ year = int(input('In which year were you born? '))
if 0<=year<100:
- print "I'll assume that by", year,
+ print("I'll assume that by", year, end=' ')
year = year + 1900
- print 'you mean', year, 'and not the early Christian era'
+ print('you mean', year, 'and not the early Christian era')
elif not (1850<=year<=2002):
- print "It's hard to believe you were born in", year
+ print("It's hard to believe you were born in", year)
return
#
if sys.argv[2:]:
month = int(sys.argv[2])
else:
- month = int(raw_input('And in which month? (1-12) '))
+ month = int(input('And in which month? (1-12) '))
if not (1<=month<=12):
- print 'There is no month numbered', month
+ print('There is no month numbered', month)
return
#
if sys.argv[3:]:
day = int(sys.argv[3])
else:
- day = int(raw_input('And on what day of that month? (1-31) '))
+ day = int(input('And on what day of that month? (1-31) '))
if month == 2 and calendar.isleap(year):
maxday = 29
else:
maxday = calendar.mdays[month]
if not (1<=day<=maxday):
- print 'There are no', day, 'days in that month!'
+ print('There are no', day, 'days in that month!')
return
#
bdaytuple = (year, month, day)
bdaydate = mkdate(bdaytuple)
- print 'You were born on', format(bdaytuple)
+ print('You were born on', format(bdaytuple))
#
todaytuple = time.localtime()[:3]
todaydate = mkdate(todaytuple)
- print 'Today is', format(todaytuple)
+ print('Today is', format(todaytuple))
#
if bdaytuple > todaytuple:
- print 'You are a time traveler. Go back to the future!'
+ print('You are a time traveler. Go back to the future!')
return
#
if bdaytuple == todaytuple:
- print 'You were born today. Have a nice life!'
+ print('You were born today. Have a nice life!')
return
#
days = todaydate - bdaydate
- print 'You have lived', days, 'days'
+ print('You have lived', days, 'days')
#
age = 0
for y in range(year, todaytuple[0] + 1):
if bdaytuple < (y, month, day) <= todaytuple:
age = age + 1
#
- print 'You are', age, 'years old'
+ print('You are', age, 'years old')
#
if todaytuple[1:] == bdaytuple[1:]:
- print 'Congratulations! Today is your', nth(age), 'birthday'
- print 'Yesterday was your',
+ print('Congratulations! Today is your', nth(age), 'birthday')
+ print('Yesterday was your', end=' ')
else:
- print 'Today is your',
- print nth(days - age), 'unbirthday'
+ print('Today is your', end=' ')
+ print(nth(days - age), 'unbirthday')
-def format((year, month, day)):
+def format(xxx_todo_changeme):
+ (year, month, day) = xxx_todo_changeme
return '%d %s %d' % (day, calendar.month_name[month], year)
def nth(n):
@@ -92,10 +93,11 @@ def nth(n):
if n == 3: return '3rd'
return '%dth' % n
-def mkdate((year, month, day)):
+def mkdate(xxx_todo_changeme1):
# Januari 1st, in 0 A.D. is arbitrarily defined to be day 1,
# even though that day never actually existed and the calendar
# was different then...
+ (year, month, day) = xxx_todo_changeme1
days = year*365 # years, roughly
days = days + (year+3)/4 # plus leap years, roughly
days = days - (year+99)/100 # minus non-leap years every century
diff --git a/Demo/scripts/update.py b/Demo/scripts/update.py
index a965e4a..d49e4b3 100755
--- a/Demo/scripts/update.py
+++ b/Demo/scripts/update.py
@@ -20,22 +20,22 @@ class FileObj:
try:
self.lines = open(filename, 'r').readlines()
except IOError as msg:
- print '*** Can\'t open "%s":' % filename, msg
+ print('*** Can\'t open "%s":' % filename, msg)
self.lines = None
return
- print 'diffing', self.filename
+ print('diffing', self.filename)
def finish(self):
if not self.changed:
- print 'no changes to', self.filename
+ print('no changes to', self.filename)
return
try:
os.rename(self.filename, self.filename + '~')
fp = open(self.filename, 'w')
except (os.error, IOError) as msg:
- print '*** Can\'t rewrite "%s":' % self.filename, msg
+ print('*** Can\'t rewrite "%s":' % self.filename, msg)
return
- print 'writing', self.filename
+ print('writing', self.filename)
for line in self.lines:
fp.write(line)
fp.close()
@@ -43,32 +43,32 @@ class FileObj:
def process(self, lineno, rest):
if self.lines is None:
- print '(not processed): %s:%s:%s' % (
- self.filename, lineno, rest),
+ print('(not processed): %s:%s:%s' % (
+ self.filename, lineno, rest), end=' ')
return
i = eval(lineno) - 1
if not 0 <= i < len(self.lines):
- print '*** Line number out of range: %s:%s:%s' % (
- self.filename, lineno, rest),
+ print('*** Line number out of range: %s:%s:%s' % (
+ self.filename, lineno, rest), end=' ')
return
if self.lines[i] == rest:
- print '(no change): %s:%s:%s' % (
- self.filename, lineno, rest),
+ print('(no change): %s:%s:%s' % (
+ self.filename, lineno, rest), end=' ')
return
if not self.changed:
self.changed = 1
- print '%sc%s' % (lineno, lineno)
- print '<', self.lines[i],
- print '---'
+ print('%sc%s' % (lineno, lineno))
+ print('<', self.lines[i], end=' ')
+ print('---')
self.lines[i] = rest
- print '>', self.lines[i],
+ print('>', self.lines[i], end=' ')
def main():
if sys.argv[1:]:
try:
fp = open(sys.argv[1], 'r')
except IOError as msg:
- print 'Can\'t open "%s":' % sys.argv[1], msg
+ print('Can\'t open "%s":' % sys.argv[1], msg)
sys.exit(1)
else:
fp = sys.stdin
@@ -80,7 +80,7 @@ def main():
break
n = prog.match(line)
if n < 0:
- print 'Funny line:', line,
+ print('Funny line:', line, end=' ')
continue
filename, lineno = prog.group(1, 2)
if not curfile or filename != curfile.filename: