친구 요청으로 작성함. wx는 필요함.


# -*- coding: utf-8 -*-
import wx
import os
import sys
reload(sys)
#sys.setdefaultencoding('cp949') # if you use windows, uncomment this line. if not, keep this line commented.

def converting(f):
    src=open(f, "r")
    header = src.readline()
    iteration = 0
    eof = "a"
    while not (eof==""):
        tar=open(f[:-4]+"_"+str(iteration)+".csv", "w")
        tar.writelines(header)
        for i in range(10000):
            eof = src.readline()
            if eof == "":
                break
            tar.writelines(eof)
        tar.flush()
        tar.close()
        iteration+=1
    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()


by snowall 2015. 5. 11. 11:32