본문 바로가기

프로그래밍

(141)
Python String(문자열) 1. 문자열문장을 표현하는 글자 모임의 변수 2. 표현방식2-1. 쌍따옴표str1 = "Life is too short" 2-2. 홀따옴표str2 = 'You need Python' 2-3. 쌍따옴표 / 홀따옴표 혼용 사용 안됨(단독 사용)2-3-1. 에러 발생 코드 예제str1 = "Life is too short' print(str1)2-3-2. 에러 발생 코드 실행 결과File "C:/python/string._error.py", line 1 str1 = "Life is too short' ^SyntaxError: EOL while scanning string literal Process finished with exit code 1 3. 문자열 연산자3-1. + (덧셈)문장과 문장을 연결하는 연산..
User agent - Python Web Crawling 1. User agent?브라우저 및 운영체제의 버전 정보를 가지고 있는 정보값user agent를 이용하여 사이트는 그 값을 감지하고 인지한다. 2. User agent 확인방법Chrome > F12 개발자모드 실행Network > F5 > 최상단 사이트 클릭Headers > Request Headers > user-agent 3. 각 브라우저별 User agent 값 브라우저 UserAgent InternetExplorer 11 Mozilla/5.0&(Windows&NT&6.3;&WOW64;&Trident/7.0;&rv:11.0)&like&Gecko InternetExplorer 10 Mozilla/5.0&(compatible;&MSIE 10.0;&Windows&NT&6.1;&WOW64;&Triden..
Python Openpyxl - Sheet Delete(excel file) 1. excle 파일에 sheet를 삭제하는 방법 2. Openpyxl 모듈 임포트from openpyxl import Workbook 3. sheet del 기본 사용법wb.remove(wb['삭제할 시트 제목']) 4. 코드 정리sheet 안에 내용을 전체 삭제하는 명령어다. 5. 예제 코드from openpyxl import Workbook wb = Workbook() dest_filename = 'sample.xlsx' ws1 = wb.active ws1.title = 'sample excel' ws1['A1'] = 'Python excel' ws2 = wb.create_sheet() ws2.title = 'sample excel2' ws2['A2'] = 'Python excel' ws3 = wb..
Python Openpyxl - Sheet Add(excel file) 1. excel 파일에 sheet를 추가하는 방법 2. Openpyxl 모듈 임포트from openpyxl import Workbook 3. sheet add 기본 사용법from openpyxl import Workbook wb = Workbook() dest_filename = '파일명.xlsx' ws1 = wb.active ws1.title = '시트1 제목' ws1['셀번호'] = '문자열' ws2 = wb.create_sheet() ws2.title = '시트2 제목' ws2['셀번호'] = '문자열' ws3 = wb.create_sheet() ws3.title = '시트3 제목' ws3['셀번호'] = '문자열' wb.save(filename = dest_filename) 4. 코드 정리4-1...
Python Openpyxl - Cell Load(excel file) 1. Openpyxl의 여러 통합 문서 모드 로드 방법 중 셀 값 로드 방법 2. Openpyxl 모듈 임포트from openpyxl import load_workbook 3. Openpyxl 기본 사용법from openpyxl import load_workbook dest_filename = '파일명.xlsx' title = '시트명' wb = load_workbook(filename = dest_filename) sheet_ranges = wb[title] print(sheet_ranges['셀'].value) 4. 코드 정리4-1. 불러들일 엑셀 파일명 지정하여 변수에 저장dest_filename = '파일명.xlsx'4-2. 불러들일 시트명 지정하여 변수에 저장title = '시트명'4-3. 4-..
Python Learn the basics Quiz 28 Q>배틀그라운드를 800시간을 한 유저가 있다.이 사람은 몇일 몇시간을 했는지 작성하는 프로그램을 만드시오. A>hours = 800 a = divmod(hours, 24) b = '800시간을 배틀그라운드를 한 유저는 {0}일 {1}시간을 한 것입니다.' print(b.format(a[0],a[1])) O>800시간을 배틀그라운드를 한 유저는 33일 8시간을 한 것입니다. Process finished with exit code 0
Python Learn the basics Quiz 27 Q>사격형의 면적과 둘레 길이를 구하는 클래스를 작성하시오. A>class Square: width = 0 height = 0 def __init__(self, width, height): self.width = width self.height = height def getArea(self): return self.width * self.height def getRound(self): return self.width * 2 + self.height * 2 O> Process finished with exit code 0
Python Openpyxl - write(excel file) 1. Python Openpyxl파이썬에 엑셀처리 패키지.특이점은 엑셀이 시스템에 설치가 되어있지 않아도 사용이 가능하다. 2. Openpyxl 설치pip install openpyxl 3. openpyxl 모듈 임포트import openpyxl 4. openpyxl 모듈 임포트 2from openpyxl import Workbook 5. openpyxl 기본 사용법from openpyxl import Workbook wb = Workbook() dest_filename = '파일명.xlsx' ws = wb.active ws.title = '시트명' ws['A1'] = 'A1 입력할 문자' wb.save(filename = dest_filename) 6. 코드 정리6-1. 작업할 워크북 생성wb = Wo..