-
<PYTHON>[socket]Flower in my dev/Python 2015. 7. 28. 16:51
[socket] - PORT번호 : 16비트 (0~65535) - 인터넷서비스PORT : 1~255 - 그 외 서비스PORT : 256~1023 - 임시 시스템 PORT : 1024~4999 5000~65535 사이 PORT 사용 - cat /etc/services : 현재 PORT 사용 정보(리눅스) - AF : Address Family - AF_UNIX : C/S가 같은 장비 - AF_INET : C/S가 다른 장비 - SOCK_STREAM : TCP - SOCK_DGRAM : UDP - socket : 소켓 객체 생성 - bind((host, port)) : 소켓 --(연결)--> host, port - listen(n) : 연결 큐 크기(최소1) - accept() : 연결 허용 - recv(b..
-
<PYTHON>[twisted.filepath.FilePath]Flower in my dev/Python 2015. 7. 14. 16:06
[filepath.FilePath] 파이썬에서 사용하는 file을 확장했다고 봐야할듯.. 대상파일이 없어도 인스턴스를 생성할 수 있다. 유용한 함수들 - child(something) : something의 결대경로 표시(FilePath형) - children() : 하위 파일 또는 디렉토리 - touch() : 파일 생성 - makedirs() : 파일 생성(디렉토리) - create() : 파일 생성(실행) - remove() : 삭제 - chmod(mode) : mode(int)의 값에 맞게 권한변경 - basename() : 이름 - dirname() : 경로 - realpath() : 경로/이름 - getAccessTime() : 마지막 접근 시간 - exists() : 실제 존내 유무(retr..
-
<PYTHON>[itertools]Flower in my dev/Python 2015. 7. 13. 09:43
[itertools] 반복 작업을 쉽게 도와준다. 내부 함수 - count() : 주어진 값에서부터 count - cycle() : 주어진 값(범위)을 계속 돌아가면서 반환 - repeat() : 주어진 값을 주어진 값 동안 반환 1 2 3 4 5 6 7 8 9 10 11 import itertools for i in itertools.count(10,1): print 1 if i == 20: break for i in itertools.count(10,2): print i if i == 20: break cs 1 2 3 4 5 6 7 8 9 10 11 12 13 import itertools for s in itertools.cycle('flower'): print s if s == 'r': break..
-
<PYTHON>[binascii]Flower in my dev/Python 2015. 7. 10. 14:33
[binascii] hex 변환 모듈 hex 외에 변환 모듈 있음. https://docs.python.org/3/library/binascii.html 1 2 3 4 5 6 7 8 9 import binascii print binascii.b2a_hex('flower') print binascii.a2b_hex('666c6f776572') print binascii.hexlify('flower') print binascii.unhexlify('666c6f776572') cs
-
<PYTHON>[collections]Flower in my dev/Python 2015. 7. 10. 11:21
[collections] - 내부 함수는 아래만 활용해 본다. Counter() deque() defaultdict() OrderedDict()namedtuple() 1. Counter() 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 import re import collections cnt = collections.Counter() words = ['flower','wing','star','flower','star','flower'] for w in words: cnt[w] += 1 print cnt print list(cnt.elements()) chk = re.findall(r'\w+', open('test.t..
-
<PYTHON>[.append & .extend]Flower in my dev/Python 2015. 7. 9. 21:06
.append 와 .extend 비교 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 list = [] list.append('first') list.extend('first') print list list = [] list.append(['second','third']) list.extend(['second','third']) print list Colored by Color Scripter cs
-
<PYTHON>[ip 변환]Flower in my dev/Python 2015. 7. 9. 11:37
[모듈을 이용한 방법] 1 2 3 4 5 6 7 import ipaddress #int ==> ip print ipaddress.IPv4Address(169328808) #ip ==> int(테스트 안됨..) print int(ipaddress.IPv4Address(169328808)) cs *에러 내용 Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/ipaddress.py", line 1271, in __init__ self._check_packed_address(address, 4) File "/usr/local/lib/python2.7/site-packages/ipadd..