본문 바로가기

전체 글

(1836)
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..
Python Pickling / Unpickling 1. Python Pickle파이썬 객체(파일)을 파일에 저장 하는 과정리스트나 클랙스 같은 텍스트가 아닌 자료형을 파일로 저장하기 위하여 사용 1-1. Pickle 모듈 임포트import pickle 1-2. Pickle 모듈 기본 사용법with open('파일명', '파일모드') as file: pickle.dump(데이터 변수, file)Pickle의 파일모드는 바이트형식으로 작성하므로 wb를 사용한다. 여기서 b는 바이너리를 의미한다. 보통 확장자는 bin / dmp를 사용한다. 물론 다른 확장자를 사용해도 무관하다. 1-3. Pickle 예제 파일>import pickle dir = 'c:/windows/dir_pro' ver = '2.0' file_load = 'c:/program/en/en...
Python Open - writelines / readlines / readline 1. writelines()Code 기본 사용법>리스트변수 = ['리스트'] with open('파일명', 'w', encoding='인코딩 방식') as file: file.writelines(리스트변수) Code 예제>list_str = ['Life is too short\n','You need Python\n'] with open('python.txt', 'w', encoding='utf-8') as file: file.writelines(list_str) Code 예제 출력물> writelines는 리스트의 있는 문자열을 파일에 작성할때 사용 하는 명령어이다.주의사항은 리스트 각 문자열 끝에 \n 개행 문자를 지정 해야된다. 2. readlines()Code 기본 사용법>with open('파일명..
Python Open - With as Open with as 기본 사용법>with open('파일명', 'r', encoding='인코딩 방식') as file: file = file.read() print(file) 1. Open with as파일을 읽고 쓰고 할 때마다 매번 아래와 같은 명령어를 사용했다.file.close()하지만 이 문구를 사용하지 않고 자동으로 할 수 있는 것이 open에 with as 함수이다. 1-1. Code>with open('i love python.txt', 'r', encoding='utf-8') as file: file = file.read() print(file) 1-1 Code 출력물>Hello, world!Welcome to Python!!Hello Process finished with exit..