레이블이 python인 게시물을 표시합니다. 모든 게시물 표시
레이블이 python인 게시물을 표시합니다. 모든 게시물 표시

2009년 2월 6일 금요일

using Excel

[엑셀 프로그램 열어서 값 넣기]

>>> import win32com.client
>>> xl = win32com.client.Dispatch("Excel.Application")
>>> xl.Visible = True
>>> xl.Workbooks.Add()

>>> exl = xl.ActiveWorkbook.ActiveSheet

>>> exl.Cells(1,1).Value = 'abc'


[엑셀의 레인지 설정]

>>> import win32com.client
>>> xl = win32com.client.Dispatch("Excel.Application")
>>> exl = xl.ActiveWorkbook.ActiveSheet

>>> print exl.Range("B2:D2")
((1.0, 2.0, 3.0),)
>>> print exl.Range("B2:F3")
((1.0, 2.0, 3.0, 4.0, 5.0), (u'a', u'b', u'c', u'd', u'e'))
>>> print exl.Range(exl.cells(2,2), exl.cells(2,5))
((1.0, 2.0, 3.0, 4.0),)


[셀 병합 하기]

>>> print exl.Range(exl.cells(4,2), exl.cells(4,5)).Merge()

wxPython

Best GUI toolkit for Python

http://www.wxpython.org/

파이썬에서 시리얼 통신하기

윈도환경에서 파이썬으로 시리얼 통신하기

필요한 것들:

1. python


2. python serial extension(pyserial) : http://sourceforge.net/projects/pyserial/


3. python win32 extension : http://starship.python.net/crew/mhammond/win32/


* 윈도환경에서 파이썬 프로그램 참고 서적: Python Programming On Win32(O'reilly)

[Open port 0 at "9600,8,N,1", no timeout]

>>> import serial
>>> ser = serial.Serial(0) # open first serial port
>>> print ser.portstr # check which port was really used
>>> ser.write("hello") # write a string
>>> ser.close() # close port

[Open named port at "19200,8,N,1", 1s timeout]

>>> ser = serial.Serial('com5', 19200, timeout=1)
>>> x = ser.read() # read one byte
>>> s = ser.read(10) # read up to ten bytes (timeout)
>>> line = ser.readline() # read a '\n' terminated line
>>> ser.close()