#!/usr/bin/python
# This program is used to expand the line number part of a phone number
# (the last 4 digits of a U.S. telephone number)
# It will also open the file specified and append to it, thus preventing
# overwriting an existing file.

def main():
    number,low,high = input("Enter number in format: '123-456',0,9999: ")
    filename = raw_input("Enter filename you would like to append to: ")

    f = open(filename, 'a')

    for i in range(low,high+1):
        print >> f, number + str("-%04d" % (i))

    f.close()

main()

Example usage:

$ ./ph_range.py
Enter number in format: '123-456',0,9999: '555-555',0,5
Enter filename you would like to append to: workfile
$ cat workfile
555-555-0000
555-555-0001
555-555-0002
555-555-0003
555-555-0004
555-555-0005