Count Lines, Words and Characters

This forum allows you to share scripts with other Zeus users. Please do not post bug reports, feature requests or questions to this forum, but rather use it exclusively for posting scripts or for the discussion of scripts that have been posted.
Post Reply
jussij
Site Admin
Posts: 2436
Joined: Fri Aug 13, 2004 5:10 pm

Count Lines, Words and Characters

Post by jussij » Wed Jun 06, 2012 8:12 am

A simple Python macro to count the lines, words and characters in the current file.

Code: Select all

import zeus
import re

def key_macro():
    numWords = 0
    numChars = 0
    numCount = 0

    # macro only works for documents
    document = zeus.is_document()

    if (document == 1):
        zeus.screen_update_disable()

        numCount = zeus.get_line_count()

        for i in range(1, numCount):
            line = zeus.get_line_text(i)

            for word in re.findall("[a-zA-Z0-9]+", line):
                numWords += 1
                numChars += len(word)

    message = "Number of characters: %d \nNumber of words: %d \nNumber of lines: %d" % (numWords, numChars, numCount)

    zeus.message_box(0, message)

key_macro() # run the macro

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 2 guests