summaryrefslogtreecommitdiffstats
path: root/Demo/scripts
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-10-10 21:07:35 (GMT)
committerGeorg Brandl <georg@python.org>2009-10-10 21:07:35 (GMT)
commit18cb94980786dddd7703ee640e9473e63de0acc3 (patch)
tree423803b6b44f8d4d4373a8cc59fd3fe5ad6002d9 /Demo/scripts
parent58d2f2689a9d50bd649b446ffde87412cd128b97 (diff)
downloadcpython-18cb94980786dddd7703ee640e9473e63de0acc3.zip
cpython-18cb94980786dddd7703ee640e9473e63de0acc3.tar.gz
cpython-18cb94980786dddd7703ee640e9473e63de0acc3.tar.bz2
Bring old demo up-to-date.
Diffstat (limited to 'Demo/scripts')
-rwxr-xr-xDemo/scripts/pp.py63
1 files changed, 31 insertions, 32 deletions
diff --git a/Demo/scripts/pp.py b/Demo/scripts/pp.py
index 0491fa9..efbe5cf 100755
--- a/Demo/scripts/pp.py
+++ b/Demo/scripts/pp.py
@@ -22,7 +22,6 @@
# - except for -n/-p, run directly from the file if at all possible
import sys
-import string
import getopt
FS = ''
@@ -36,7 +35,7 @@ PFLAG = 0
try:
optlist, ARGS = getopt.getopt(sys.argv[1:], 'acde:F:np')
except getopt.error, msg:
- sys.stderr.write(sys.argv[0] + ': ' + msg + '\n')
+ sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
sys.exit(2)
for option, optarg in optlist:
@@ -47,7 +46,7 @@ for option, optarg in optlist:
elif option == '-d':
DFLAG = 1
elif option == '-e':
- for line in string.splitfields(optarg, '\n'):
+ for line in optarg.split('\n'):
SCRIPT.append(line)
elif option == '-F':
FS = optarg
@@ -81,31 +80,31 @@ if CFLAG:
elif NFLAG:
# Note that it is on purpose that AFLAG and PFLAG are
# tested dynamically each time through the loop
- prologue = [ \
- 'LINECOUNT = 0', \
- 'for FILE in ARGS:', \
- ' \tif FILE == \'-\':', \
- ' \t \tFP = sys.stdin', \
- ' \telse:', \
- ' \t \tFP = open(FILE, \'r\')', \
- ' \tLINENO = 0', \
- ' \twhile 1:', \
- ' \t \tLINE = FP.readline()', \
- ' \t \tif not LINE: break', \
- ' \t \tLINENO = LINENO + 1', \
- ' \t \tLINECOUNT = LINECOUNT + 1', \
- ' \t \tL = LINE[:-1]', \
- ' \t \taflag = AFLAG', \
- ' \t \tif aflag:', \
- ' \t \t \tif FS: F = string.splitfields(L, FS)', \
- ' \t \t \telse: F = string.split(L)' \
+ prologue = [
+ 'LINECOUNT = 0',
+ 'for FILE in ARGS:',
+ ' \tif FILE == \'-\':',
+ ' \t \tFP = sys.stdin',
+ ' \telse:',
+ ' \t \tFP = open(FILE, \'r\')',
+ ' \tLINENO = 0',
+ ' \twhile 1:',
+ ' \t \tLINE = FP.readline()',
+ ' \t \tif not LINE: break',
+ ' \t \tLINENO = LINENO + 1',
+ ' \t \tLINECOUNT = LINECOUNT + 1',
+ ' \t \tL = LINE[:-1]',
+ ' \t \taflag = AFLAG',
+ ' \t \tif aflag:',
+ ' \t \t \tif FS: F = L.split(FS)',
+ ' \t \t \telse: F = L.split()'
]
- epilogue = [ \
- ' \t \tif not PFLAG: continue', \
- ' \t \tif aflag:', \
- ' \t \t \tif FS: print string.joinfields(F, FS)', \
- ' \t \t \telse: print string.join(F)', \
- ' \t \telse: print L', \
+ epilogue = [
+ ' \t \tif not PFLAG: continue',
+ ' \t \tif aflag:',
+ ' \t \t \tif FS: print FS.join(F)',
+ ' \t \t \telse: print \' \'.join(F)',
+ ' \t \telse: print L',
]
else:
prologue = ['if 1:']
@@ -114,10 +113,10 @@ else:
# Note that we indent using tabs only, so that any indentation style
# used in 'command' will come out right after re-indentation.
-program = string.joinfields(prologue, '\n') + '\n'
+program = '\n'.join(prologue) + '\n'
for line in SCRIPT:
- program = program + (' \t \t' + line + '\n')
-program = program + (string.joinfields(epilogue, '\n') + '\n')
+ program += ' \t \t' + line + '\n'
+program += '\n'.join(epilogue) + '\n'
import tempfile
fp = tempfile.NamedTemporaryFile()
@@ -125,6 +124,6 @@ fp.write(program)
fp.flush()
if DFLAG:
import pdb
- pdb.run('execfile(%r)' % (tfn,))
+ pdb.run('execfile(%r)' % (fp.name,))
else:
- execfile(tfn)
+ execfile(fp.name)