mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
Clean up syntax for some scripts.
This commit is contained in:
parent
aba74bddd6
commit
e4a3380bb0
7 changed files with 115 additions and 87 deletions
|
@ -9,8 +9,9 @@ import sys
|
|||
import re
|
||||
import getopt
|
||||
|
||||
|
||||
def main():
|
||||
bufsize = 64*1024
|
||||
bufsize = 64 * 1024
|
||||
reflags = 0
|
||||
opts, args = getopt.getopt(sys.argv[1:], "i")
|
||||
for o, a in opts:
|
||||
|
@ -24,11 +25,11 @@ def main():
|
|||
try:
|
||||
prog = re.compile(pattern, reflags)
|
||||
except re.error as msg:
|
||||
usage("error in regular expression: %s" % str(msg))
|
||||
usage("error in regular expression: %s" % msg)
|
||||
try:
|
||||
f = open(filename)
|
||||
except IOError as msg:
|
||||
usage("can't open %s: %s" % (repr(filename), str(msg)), 1)
|
||||
usage("can't open %r: %s" % (filename, msg), 1)
|
||||
f.seek(0, 2)
|
||||
pos = f.tell()
|
||||
leftover = None
|
||||
|
@ -49,16 +50,17 @@ def main():
|
|||
del lines[0]
|
||||
else:
|
||||
leftover = None
|
||||
lines.reverse()
|
||||
for line in lines:
|
||||
for line in reversed(lines):
|
||||
if prog.search(line):
|
||||
print(line)
|
||||
|
||||
|
||||
def usage(msg, code=2):
|
||||
sys.stdout = sys.stderr
|
||||
print(msg)
|
||||
print(__doc__)
|
||||
sys.exit(code)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue