-
<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..
-
<PYTHON>[locale]Flower in my dev/Python 2015. 7. 9. 10:52
[locale] 문자열을 표현할 때, 돈을 표현할 일이 생긴다. 그럼 세자리마다 [,]를 찍어주어야 하는데 그때 사용한다. 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 locale locale.setlocale(locale.LC_ALL, '') n = 12039238273592834.123123 s = locale.format('%.2f', n, 1) print s n = 1209312037141.1231254 s = locale.format('%.4f', n, 1) print s n = 12312412512.12352 s = locale.format('%.3f', n, 1) print s n = 123..
-
<PYTHON>[pysftp]Flower in my dev/Python 2015. 7. 2. 12:58
[pysftp] sftp를 사용하는 모듈. 사용법 12345678910111213141516171819202122232425262728293031323334353637import pysftp with pysftp.Connection(’hostname’, username=’me’, password=’secret’) as sftp:sftp = pysftp.Connection(host, username='id', password='pw')#연결(두가지 방법) sftp.chdir(path)#작업 디렉토리로 이동 sftp.mkdir(name)#필요 디렉토리 생성 sftp.chmod(path)#생성된 디렉토리 권한 변경 sftp.put(filename, preserve_mtime=True)#파일 전송 sftp.ge..
-
<PYTHON>[coroutine]Flower in my dev/Python 2015. 7. 1. 11:25
[coroutine] yield가 변했다. coroutine의 탱커(?) 제너레이터를 만들어주는 것도 있지만 coroutiine에서 함수의 내부에서 함수의 stop point 또는 data input 으로 사용되어 local 을 global처럼 유지시키면서 해당 함수를 입력받은 값으로 동작시켜 유지시킨다. 더욱 자세한 내용은 아래 url에서 확인 http://www.dabeaz.com/coroutines/ 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 def coroutine(func): def start(*args, **kwargs): print ">>>args : ", args print ">>>kwargs : ", kwar..