Показать сообщение отдельно

[Python] Счетчик Строк
  #5  
Старый 23.06.2009, 22:33
login999
Постоянный
Регистрация: 12.06.2008
Сообщений: 654
Провел на форуме:
4512757

Репутация: 973


По умолчанию [Python] Счетчик Строк

[Python] Элементарный скрипт для подсчета строк в файлах.
Пригодится для проверки говночекеров, да и вообще так (по крайней мере мну сегодня пригодился)
Скрипт с гуем, пэтому требует Tkinter (на windows стоит по умолчанию)
В режиме "Без дублей" файл грузится в оперативку, поэтому поаккуратнее там
Скрин:


Код:
#!usr/bin/env python
# -*- coding:utf-8 -*-
# files length counter
# (c) login999

from Tkinter import *
from tkMessageBox import showerror
from tkFileDialog import askopenfilename
LastCounter = 0
NowCounter = 0
AllCounter = 0

def Count():
    global LastCount
    global NowCount
    global AllCount
    global AllCounter
    global NowCounter
    global LastCounter
    LastCounter = NowCounter
    NowCounter = 0
    try:
        with open(askopenfilename()) as accs:
            for _ in accs:
                NowCounter += 1
                AllCounter += 1
        LastCount["text"] = LastCounter
        NowCount["text"] = NowCounter
        AllCount["text"] = AllCounter
    except Exception, e:
        showerror(u"Ошибка", e)
        
def NODUP():
    global LastCount
    global NowCount
    global AllCount
    global AllCounter
    global NowCounter
    global LastCounter
    LastCounter = NowCounter
    NowCounter = 0
    try:
        with open(askopenfilename()) as accs:
            for _ in set(accs):
                NowCounter += 1
                AllCounter += 1
        LastCount["text"] = LastCounter
        NowCount["text"] = NowCounter
        AllCount["text"] = AllCounter
    except Exception, e:
        showerror(u"Ошибка", e)
        
def Clear():
    global LastCount
    global NowCount
    global AllCount
    global AllCounter
    global NowCounter
    global LastCounter
    NowCounter = 0
    LastCounter = 0
    AllCounter = 0
    LastCount["text"] = LastCounter
    NowCount["text"] = NowCounter
    AllCount["text"] = AllCounter

MainWindow = Tk()
MainWindow["bd"] = 5
MainWindow.title(u"Счетчик Строк")
MainWindow.resizable(width=False, height=False)
ButtonsFrame = Frame(MainWindow)
CountButton = Button(ButtonsFrame, text=u"Посчитать", width=11, command=Count)
NODUPButton = Button(ButtonsFrame, text=u"Без дублей", width=11, command=NODUP)
ClearButton = Button(ButtonsFrame, text=u"Очистить", width=11, command=Clear)
CountButton.grid(row=0, column=0)
NODUPButton.grid(row=1, column=0)
ClearButton.grid(row=2, column=0)
ButtonsFrame.grid(row=0, column=0, sticky="w")
LinesLabel = LabelFrame(MainWindow, text=u"Количество строк")
LastLabel = Label(LinesLabel, text=u"Последний :", anchor="w", width=12)
LastCount = Label(LinesLabel, text=LastCounter, width=8)
NowLabel = Label(LinesLabel, text=u"Нынешний :", anchor="w", width=12)
NowCount = Label(LinesLabel, text=NowCounter, width=8)
AllLabel = Label(LinesLabel, text=u"Всего :", anchor="w", width=12)
AllCount = Label(LinesLabel, text=AllCounter, width=8)
LastLabel.grid(row=0, column=0)
LastCount.grid(row=0, column=1)
NowLabel.grid(row=1, column=0)
NowCount.grid(row=1, column=1)
AllLabel.grid(row=2, column=0)
AllCount.grid(row=2, column=1)
LinesLabel.grid(row=0, column=1, sticky="w")
MainWindow.mainloop()

Последний раз редактировалось login999; 24.06.2009 в 00:08.. Причина: Поправил
 
Ответить с цитированием