Looking for a Python Program/Tool That Will Add Line Numbers to a txt File

JussiJ jussij at zeusedit.com
Sun Feb 17 19:47:53 EST 2008


On Feb 14, 5:54 pm, "W. Watson" <wolf_tra... at invalid.com> wrote:

> See Subject. It's a simple txt file, each line is a Python stmt,
> but I need up to four digits added to each line with a space
> between the number field and the text.

FWIW here is a Zeus editor, Python macro script to do this:

    import zeus

    def key_macro():
        zeus.screen_update_disable()

        # get the line is the current document
        line_total = zeus.get_line_count()

        # message in status bar
        zeus.message("Line Count: %d" % (line_total))

        # write the line number to the start of each line
        for i in range(1, line_total + 1):
            zeus.set_line_pos(i, 1)
        	number = "%4d " % (i)
            zeus.write(number)

        zeus.screen_update_enable()
        zeus.screen_update()

    key_macro() # run the macro

To use the script, just load the text file into Zeus and then
run the macro above from within Zeus.

Jussi Jumppanen
Author: Zeus for Windows IDE
http://www.zeusedit.com



More information about the Python-list mailing list