Coding/Python 삽질기2011. 1. 12. 00:24
#-*- coding: cp949 -*-
# Name        : py_patten.py
# Author      : chobocho.com
# Version     :
# Copyright   :
# Description : simple number change 
#

from Tkinter import *
import tkMessageBox
 
save_file_name = "test.txt"
names = [ 'number1', 'number2' ]
table  = { names[0] : '100', names[1] : '200' } 

text_data = """Trees are  %(number1)s 
won,  %(number2)s won!""" 
 
class App:
    def __init__ (self, master):
    
        self.target_file_name = save_file_name
        
        frame = Frame(master)
        frame.pack()
        
        f3 = Frame(frame, width = 100, height = 40)
        f3.grid(row = 0, column = 0)
        
        self.label_1 = Label(f3, text= names[0])
        self.label_1.grid(row = 0, column = 0, sticky = W) 
        self.input_1 = Entry(f3)
        self.input_1.grid(row = 0, column = 1)

        self.label_2 = Label(f3, text= names[1])
        self.label_2.grid(row = 1, column = 0, sticky = W)
        self.input_2 = Entry(f3)
        self.input_2.grid(row = 1, column = 1)

        # 버튼을 그려주는 부분
        f4 = Frame(frame, width = 100, height = 40)
        f4.grid(row = 1, column = 0)
        

        self.info_button = Button(f4, text="Make", command = self.MakeFile)
        self.info_button.grid(row = 0, column = 0)
        self.info_button = Button(f4, text="Info", command = self.ShowInfo)
        self.info_button.grid(row = 0, column = 1)

    def ShowInfo(self):
        tkMessageBox.showinfo("Information","http://chobocho.com\nVersion 0.2")

    def MakeFile(self):
        self.value1 = self.input_1.get()
        self.value2 = self.input_2.get() 
        
        table[ names[0] ] = self.value1
        table[ names[1] ] = self.value2
        
        self.data = text_data % table

        target = file(self.target_file_name, 'w')
        target.write(self.data)
        target.close()

               
#----------------------------------------------------------
# main
if __name__ == "__main__":      
    root = Tk()
    app = App(root)
    root.mainloop()

'Coding > Python 삽질기' 카테고리의 다른 글

[Python] Undo / Redo 구현하기  (0) 2011.06.16
http://www.pythonchallenge.com...Level6  (0) 2010.12.13
http://www.pythonchallenge.com...Level5  (0) 2010.12.13
Posted by chobocho
Coding/Ruby2011. 1. 8. 02:08
# save image from web
# 2011. 1. 7

require 'open-uri'

def read_url_file(url_name_, number_)
    open(url_name_) { |from| $data = from.read }
    File.open("#{number_}.jpg", "wb:binary") { |to| to.write($data) }
end

read_url_file("http://chobocho.com/photo/sydney.jpg", 2)

'Coding > Ruby' 카테고리의 다른 글

[Ruby] Simple file copy example  (0) 2011.01.07
Posted by chobocho
Coding/Ruby2011. 1. 7. 23:48
# simple file copy
# 2011. 1. 7

File.open("test.png", "rb:binary") { |from| $data = from.read }
File.open("test2.png", "wb:binary") { |to| to.write($data) }

'Coding > Ruby' 카테고리의 다른 글

[Ruby] Save image from web  (0) 2011.01.08
Posted by chobocho
Coding/Python 삽질기2010. 12. 13. 01:29


 

import re
import zipfile


def main():

    target = zipfile.ZipFile("channel.zip", 'r')
       
    number = "90052"
    filename = number + ".txt"
    comment = ""

    while 1:   
        print filename
        data = target.read(filename)
        data_ = re.findall("nothing is ([0-9]+)", data)
        if data_:
            comment += target.getinfo(filename).comment
            filename = "".join(data_) + ".txt"
        else:
            break
       
        print comment
         
if __name__ == "__main__":
    main()


'Coding > Python 삽질기' 카테고리의 다른 글

간단한 반복 작업 매크로  (0) 2011.01.12
http://www.pythonchallenge.com...Level5  (0) 2010.12.13
http://www.pythonchallenge.com...Level4  (0) 2010.12.13
Posted by chobocho
Coding/Python 삽질기2010. 12. 13. 01:00


 

import pickle

def main():
    fp = open("banner.p", 'rb')
    data = pickle.load(fp)
   
    for li in data:
        line = ""
        for ch, count in li:
            line += ch*count
        print line
   
       
if __name__ == "__main__":
    main()


Posted by chobocho
Coding/Python 삽질기2010. 12. 13. 00:37


 

import urllib
import re


def main():

    url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="
   
    url_to = url + "12345"
    #url_to = url + "46059" # After get new messages.
   
    while 1:
        source = urllib.urlopen(url_to)
        data = source.read()
        number = re.findall("nothing is ([0-9]+)", data)
        if number:
           url_to = url + "".join(number)
           print url_to
        else:
           break
       
    print data
   
   
if __name__ == "__main__":
    main()

Posted by chobocho
Coding/Python 삽질기2010. 12. 12. 23:11


 

import re

data_ = """_abaAAAbCCC"""

def main():
    p = re.compile ('[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}')
    m = p.findall(data_)
   
    if m:
        print m
        for idx in m:
            print idx[4],
   
   
if __name__ == "__main__":
    main()

Posted by chobocho
Coding/Python 삽질기2010. 12. 6. 23:34
data='''
find at source code...
'''

def main():
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    result = filter(lambda x : x in alphabet, data)
   
    print result
   
if __name__ == "__main__":
    main()

'Coding > Python 삽질기' 카테고리의 다른 글

http://www.pythonchallenge.com...Level3  (0) 2010.12.12
[Python] 파일 zip으로 압축하기  (0) 2010.10.25
1000!  (0) 2010.07.14
Posted by chobocho
Coding/JavsScript 삽질기2010. 11. 30. 00:54

'Coding > JavsScript 삽질기' 카테고리의 다른 글

글자수 세는 자바 스크립트  (2) 2011.11.15
Hex2Ascii Javascript code  (0) 2010.06.15
[Flex] HEXA v0.1  (0) 2009.08.15
Posted by chobocho
Coding/Perl 삽질기2010. 11. 12. 01:26
#
# Date : 2010. 11. 12
#
# Author : chobocho.com
#
# Description : 패턴에 포함된 라인을 출력해주는 스크립트
###############################################
# File Name

$filename = "express.ini";

open (EXP_FILE, "<".$filename) || die $!;
@expressions = <EXP_FILE>;
close(EXP_FILE);

print "!!! chobocho filter V0.01 !!!\n";
print "-----------------------------\n";
print @expressions;
print "\n---------------------------\n";

{
    if (-f $ARGV[0]) 
    {
        print "!!! Read ".$ARGV[0]."!!!\n";
        print "\n---------------------------\n";
    
        open (IN_FILE, "<".$ARGV[0]) || die $!;
         
        while (my $line = <IN_FILE>) 
        {
            foreach $expression(@expressions)
            {
                if ( $line =~ /$expression/ )
                {
                    print $line;
                }
            }
        }

        close (IN_FILE);
    } 
}


[실행파일]
Posted by chobocho