Python/Python Programming
-
[Python] datetime.strftime를 이용한 날짜와 시간 변환Python/Python Programming 2019. 4. 11. 13:31
from datetime import datetime timenow = datetime.now() # Current Time dt = timenow.strftime('%m-%d-%Y, %H:%M:%S') # datetime print(dt) 04-11-2019, 13:20:17 year1 = timenow.strftime('%Y') # Year with century as a decimal number print(year1) 2019 year2 = timenow.strftime('%y') # Year without century as a zero-padded decimal number print(year2) 19 month1 = timenow.strftime('%m') # Month as a zero-p..
-
파이썬(Python) 설치Python/Python Programming 2019. 3. 17. 10:02
파이썬(python) 다운로드 : https://www.python.org - 운영체제 플랫폼에 맞게 다운로드. (현재는 3.7.2)- Windows XP와 그 이전버전의 운영체제는 3.5 이상버전을 사용할 수 없음 - Install Now : 기본설치- Customize installation : 사용자 설치 - Add_Python 3.7 PATH : PATH 환경변수가 필요없다면 체크 않해도 된다. 필자는 환경변수를 체크하고, 사용자 설치로 진행 - 디렉토리는 별도로 생성- Debug 옵션 필요시 체크 파이썬(Python) 3.7.2가 정상적으로 설치되었다.
-
[Python] ODBC driver를 이용한 mssql 연결Python/Python Programming 2018. 12. 29. 16:28
# pyodbc를 사용하여 mssql 연결 https://docs.microsoft.com/ko-kr/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-2017 1. pip install pyodbc 를 이용하여 모듈설치 2. odbc 최신 다운로드 : https://docs.microsoft.com/en-us/sql/connect/odbc/microsoft-odbc-driver-for-sql-server?view=sql-server-2017 3. 접속테스트 import pyodbc server = 'tcp:192.168.x.x' database = 'dbname' username ..
-
[Python] FTP TLS Download 다운로드Python/Python Programming 2018. 8. 7. 01:44
DOCS : https://docs.python.org/3.6/library/ftplib.html?highlight=ftp_tls from ftplib import FTP_TLS ftps = FTP_TLS('host') ftps.login('host', 'passwd') ftps.prot_p() filename = 'test1.txt' myfile = open(filename, 'wb') ftps.retrbinary('RETR %s' % filename, myfile.write) ftps.close()
-
[Python] Comparison of Datetime Type Using PythonPython/Python Programming 2018. 6. 15. 18:33
파이썬의 datetime 타입끼리 비교 연산이 가능하며, 결과는 True, False 로 리턴 from datetime import datetime from datetime import timedelta today = datetime.today() yesterday = today - timedelta(days=1) compare = today > yesterday print(compare) True
-
[ Python ] shutil모듈의 rmtree 메소드를 이용한 하위 디렉토리와 파일 삭제Python/Python Programming 2018. 5. 22. 21:54
shutil.rmtree로 삭제된 파일은 복구 할 수 없으므로, 유의하여 진행한다. 실무에서 사용할 경우 본인환경에서 충분한 테스트를 수행해야 한다. shutil.rmtree('경로')와 같이 이용할 수 있으나 한번 삭제되면 복구될 수 없으니 고민하여 수행하는 것이 좋다. 1. 삭제될 경로확인 2. 해당 명령어가 실행될 경우 삭제되는 폴더와 파일 3. 실행 전 Y / N 트리거 파일삭제 전 os.path.walk를 이용해 삭제리스트를 출력한다. 폴더와 파일수가 많으면 os.listdir을 이용해 1depth만 출력할 수 있다. 경로는 os.abspath를 이용해 상대경로가 입력되더라도 절대경로가 출력된다. 파일작업시 '절대경로'와 '상대경로'의 결과값이 달라질 있으니 중요하고, 또 중요하다. import..
-
[Python] 3.6+에서 사전자료형(Dict)은 입력순서를 보존Python/Python Programming 2018. 5. 19. 16:40
DOCS : https://docs.python.org/3/whatsnew/3.6.html 파이썬 3.6+ 에서는 사전입력 순서를 보존한다. 그렇다면 굳이 자료구조의 collections.OrderedDict()를 사용할 필요가 없다는 것인가. 또한 재구현으로 3.5 보다 메모리를 20% ~ 25% 덜 사용하는 등 개선이 있다. 사전을 차례로 입력하고 약 10번 정도 출력해 보았다. dic = {} dic['제주도'] = '한라산' dic['서울'] = '북한산' dic['강원도'] = '설악산' dic['충청북도'] = '속리산' dic['전라도'] = '속리산' cnt = 0 while cnt