Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- from os.path import splitext
- def write_range(start, end, handle):
- if start == end:
- handle.write("{0}\n".format(start))
- elif end < 0:
- pass
- else:
- handle.write("{0},{1}\n".format(start, end))
- try:
- file_in = sys.argv[1]
- except IndexError:
- print("Usage: {0} [file with list of combed frames]".format(sys.argv[0]))
- raise SystemExit
- last = -9
- start = 0
- fparts = splitext(file_in)
- file_out = "{0}-range{1}".format(fparts[0], fparts[1])
- try:
- with open(file_in) as in_f:
- try:
- with open(file_out, 'w') as o:
- for line in in_f:
- curr = int(line)
- if curr - last > 4:
- write_range(start, last, o)
- start = curr
- last = curr
- write_range(start, last, o)
- except IOError:
- print("Cannot open {0} for writing.".format(file_out))
- raise SystemExit
- except IOError:
- print("Cannot open: {0}".format(file_in))
- raise SystemExit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement