Everything will be Okay in the end. If it not okay, it is not the end.

반복되는 수작업은 무조건 자동화로 해결.

오늘도 에어컨이 너무 빵빵한 실험실에서 하루종일 실험을 반복했다.

그래도 다행인 것은 문제로 보이는 현상의 원인이 우리쪽이 아니라 상대방 장비 쪽이라는 것을 확인했다는 점이다.

그 과정에서 매번 로그 정보를 분석해야 하는데 하도 짜증나고, 실수하기 쉬운 일이라(복잡한 파일에서 정확한 숫자 정보만을 읽어서 처리해야 한다) 결국 로그 파일을 분석해서 내가 원하는 형태로 포매팅하는 python script를 작성했다

덕분에 그 전에는 로그 파일을 [...]

log activity with launchy

make a directory named c:scratch create a python script log.py and save the same directory

import time import sys

now = time.localtime(time.time()) tim=time.strftime(”%Y/%m/%d %H:%M:%S”, now)

fp = open(”c:scratchmyLog.txt”, “a”) message = ” “.join(sys.argv[1:]) print >>fp, tim+” “+message

fp.close()

register that directory and *.py in launchy category and rescan Restart launchy invoke launchy and type “log” and type tab jot down log message and enter

Reference http://benkraal.wordpress.com/2007/05/16/launchy-append-text-to-a-file-from-anywhere/

Python CSV 파일 사용하기 등

1. CSV 파일 읽기/쓰기 writer = csv.writer(open(”test.csv”, “wb+”)) writer.writerow(csvRow) 2. 간단한 샘플 프로그램을 볼 수 있는 곳

SimplePrograms

아주 사소하지만 유용한 프로그램들이 많이 있다.

3. 정규식 사용하기

정수건 소수건 음수건, 양수건 숫자란 숫자는 모두 뽑아서 리스트로 돌려주기 m = re.findall(r”-?\d+.?\d*”,oneLine) via http://mail.python.org/pipermail/python-list/2004-September/284235.html 4. 파일명에서 확장자 제외한 파일 이름 얻어내기

>>> import os >>> os.path.splitext(’this.is.my.file.avi’)

(’this.is.my.file’, ‘.avi’)

“Hello World” from ipod touch

iMac:~ cychong$ ssh root@10.0.1.198 root@10.0.1.198’s password: Last login: Wed Dec 26 22:31:55 2007 from 10.0.1.200 # ls HanRSS_20071225.opml Library Media root.zip

# python Python 2.5.1 (r251:54863, Jul 27 2007, 12:05:57) [GCC 4.0.1 LLVM (Apple Computer, Inc. build 2.0)] on darwin Type “help”, “copyright”, “credits” or “license” for more information. >>> print “hello world” hello world >>>

써놓고 보니 뭔 의미가 있는 지 애매해서 제목 [...]

Today’s hack

python을 이용한 flickr uploader.

코드를 보니 이 녀석 역시 지정된 디렉토리 이하에서 파일들(확장자가 jpg, gif, png인 놈)을 찾아서 리스트를 만든 후 그 리스트에 있는 것들을 하나씩 flickr로 올리는 방식이다.

지금 2005년도 사진을 올리라고 했는데 전체 몇 개중에 몇 개나 올라갔는지 확인하는 기능이 없어 쬐금 아쉽다. 진작 알았으면 간단하게 몇 줄 추가하면 될 것인데…

수정본: 미리 [...]