본문 바로가기

Python

[Python] 동시성(Concurrency), 병렬성(Parallelism) 동시성(Concurrency) 프로그래밍 - 동시에 실행되는 것처럼 보이는 것 - Thread 여러 개를 번갈아 가면서 실행 - Multi-threading import threading import time # thread에서 실행할 함수 def work(): print("[sub] start") keyword = input("[sub] 검색어를 입력하세요 >>>") print(f"[sub] {keyword}로 검색을 시작합니다.") print("[sub] end") # mainthread 실행 print("[main] start") worker = threading.Thread(target=work) # daemon을 사용하면 mainthread가 종료될 때 subthread도 같이 종료됨 worke.. 더보기
[Python] csv 파일 쓰기, 읽기 csv 파일 쓰기 import csv data = [ ["Regression", "qualification ", "rmse"], ["Classification", "quantification", "AUC"] ] file = open("./models.csv", "w", newline="", encoding="utf-8-sig") # newline : windows의 경우 한 줄씩 띄어지게 되는데 그것을 방지 # encoding="utf-8-sig" : windows의 경우, csv 파일이 vs code editor에서 csv 파일 깨지지 않게 설정 writer = csv.writer(file) for d in data: writer.writerow(d) # 한 줄씩 row로 쌓이게 됨 file.close.. 더보기
[Python] pickle 파일 작성 및 읽기 Pickle 파일 작성 import pickle data = { "계획1" : "논문 스터디", "계획2" : "중국어 공부" } file = open("data.pickle", "wb") # wb: wrtie binary -> binary 형태로, 컴퓨터가 바로 읽을 수 있음 pickle.dump(data, file) # data를 file에 담음 file.close() Pickle 파일 읽기 import pickle file = open("data.pickle", "rb") data = pickle.load(file) print(data) file.close() With 구문 # with 구문 X file = open("data.txt", "r", encoding = "utf8") data = f.. 더보기