# -*- coding: utf-8 -*-
import wx
import os
import sys
reload(sys)
sys.setdefaultencoding('cp949')

def converting(f):
    tar=open(f[:-4]+"_processed.txt", "w")
    src=open(f, "r")
    src.readline()
    src.readline()
    src.readline()
    while True:
        d=src.readline()
        if d[0]=="\"":
            break   
        d=d.replace(",","\t")
        tar.writelines([d])
    tar.flush()
    tar.close()
    src.flush()
    src.close()
   
class mainframe(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        dig = wx.FileDialog(None, message="Choose data files", style = wx.FD_MULTIPLE)
        if dig.ShowModal() == wx.ID_OK:
            for fn in dig.GetPaths():
                converting(fn)

class conv(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        main = mainframe(None, -1, "")
        self.SetTopWindow(main)
        main.Show(True)
        main.Show(False)
        exit()
        return 1

if __name__ == "__main__":
    conv = conv(0)
    conv.MainLoop()


wxPython을 이용한 프로그램이다. 대충 분석해 보면 알겠지만, sys.setdefaultencoding에 cp949를 쓴것은 윈도우 전용이라는 뜻이고 리눅스나 맥에서는 필요 없다.(안쓰면 된다.)

converting(f)에 파일을 하나씩 받아서 처리하는 함수를 구현하면 된다. 파일 목록을 받아서 하나씩 집어넣어주는 반복문은 mainframe안에 for fn in dig.GetPaths()이다.

 

파일 하나씩은 처리하겠는데 수백개 처리를 자동화 시켜야 할 때 쓰면 좋은 템플릿이다. 직접 만들었음.

by snowall 2014. 8. 15. 01:33