-
<PYTHON> UDP_Echo_ServerFlower in my dev/Python 2015. 4. 21. 15:04
1 2 3 4 5 6 7 8 9 10 11 12 from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor class EchoUDP(DatagramProtocol): def datagramReceived(self, datagram, address): print "Received from address: " + str(address) print str(datagram) self.transport.write(datagram, address) print "Starting server." reactor.listenUDP(9001, EchoUDP()) reactor.run() Colored by Color S..
-
<PYTHON>시스템 정보 가져오기(CPU, RAM, DISK)Flower in my dev/Python 2015. 4. 21. 14:03
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 import time, random import psutil import os # Return CPU temperature as a character string def getCPUTemperature(): res = os.popen('vcgencmd measure_temp').readline() return(res.replace("temp=","").replace("'C\n","")) # Return RAM information (unit=kb) in a list # Index 0: total R..
-
<PYTHON>[loop]Flower in my dev/Python 2015. 4. 14. 14:11
-사전 반복 iterkeys() itervalues() iteritems() -파일 반복 f = open('test.txt') for line in f: print line -숫자 반복 count() for n in count(10): print n 10부터 끝없이 출력된다. -객체 반복 cycle() for n in cycle(['a','b','c']): print n -발생자 generate_ints() for n in generate_ints(5): print n 0 1 2 3 4 5 -짝,홀 반복 for n in range(1, 10, 2): print n for n in range(2, 10, 2): print n 리스트로 묶기 list = [n for n in range(100) if n % ..
-
<PYTHON>[리스트, 튜플, 사전]Flower in my dev/Python 2015. 4. 13. 16:24
리스트 a = [1,2,3,'flower'] 리스트 중첩 a = [1,2,3,'flower', ['rose','daisy'] ] a.append() 자료를 리스트 끝에 추가 a.insert() 자료를 지정된 위치에 삽입 a.index() 요소 검색 인덱스 반환 a.count() 요소 개수 알아내기 a.sort() 리스트 정렬 a.reverse() 자료 순서 바꾸기 a.remove() 지정 자료 값 한 개 삭제 a.pop() 리스트의 지정된 값 하나를 읽어 내고 삭제 a.extend() 리스트 추가 스택 list.append() list.pop() 큐 list.append() list.pop(0) 튜플 a = (1,2,3,'flower') 사전 a = {1:'flower', 2:'sky', 3:'earth..
-
<PYTHON>[내장함수]Flower in my dev/Python 2015. 4. 13. 15:21
abs abs(x)는 숫자값을 입력값으로 받았을 때, 그 숫자의 절대값을 돌려주는 함수이다.>>> abs(3) 3 >>> abs(-3) 3 >>> abs(1+2j) 2.2360679774997898 >>> 복소수의 절대값은 다음과 같이 구해진다.abs(a + bj) = sqrt (a^2+b^2) chr chr(i)는 정수 형태의 아스키코드값을 입력으로 받아서 그에 해당하는 문자를 출력하는 함수이다.>>> chr(97) 'a' >>> chr(48) '0' >>> dir dir은 객체가 가지고 있는 변수나 함수를 리스트 형태로 보여준다. 아래의 예는 리스트와 딕셔너리 객체의 관련 함수들(메소드)을 보여주는 예이다. 우리가 앞서서 살펴보았던 관련함수들을 구경할 수 있을 것이다.>>> dir([1,2,3]) [..
-
<PYTHON> twisted 설치Flower in my dev/Python 2015. 4. 8. 11:09
소스 다운로드 http://twistedmatrix.com/trac/ wget https://pypi.python.org/packages/source/T/Twisted/Twisted-15.0.0.tar.bz2 다운로드 후 tar jxvf Twisted-15.0.0.tar.bz2 cd Twisted-15.0.0.tar.bz2 python setup.py install 그럼 설치 끝 root로 해야 됨.. 에러는 캡처 못함.. 그리고 zope.interface 에러가 있는데 위와 같은 방법으로 설치 하면 끝.
-
db 생성Flower in my dev/SQLite3 2015. 4. 8. 10:34
명령 뒤에 db명을 적어주면 끝 하지만 아무작업을 안하면 db가 생성이 안된다는 것 sqlite3 test.db 아무 테이블이나 만들어주기. create table account( id integer primary key, pw integer not null ); 초기 데이터를 넣고 확인 insert into account(id, pw) values('1234', '5678'); select * from account; 결과를 보기 힘들면 .header on .mode column 그리고 다시 select * from account;