python snippets

python snippets

Python 3.12에서 ImportError: No module named matplotlib 에러가 뜰 때

1. 문제 상황 가상환경 안에서 설치해서 이 오류가 발생하는 것인지는 모르겠으나, 일반적인 방법인 pip install matplotlib을 이용해서 설치 후 사용하였을 때 다음과 같은 오류가 발생하였음. 2. 일반적인 해결법 보통 pip uninstall matplotlib 명령어로 삭제 후 재설치만 해도 해결되는 경우가 많다고 하나, 내 경우에 적용되지 않았음. 3. 내가 사용한 해결법 pip uninstall matplotlib으로 삭제 후 pip3 install matplotlib으로 재설치하니 해결 됨. *. VirtualEnv에서 폰트 사용하기 또한, VirtualEnv 가상환경에서 plt.rc("font", family="NanumGothic")으로 폰트 설정 시, 폰트를 불러오지 못하는 현..

python snippets

Python으로 문자 일괄치환

1. 전각 -> 반각 (unicodedata 이용) import unicodedata def full_to_half(text): return unicodedata.normalize('NFKC', text) print(full_to_half('Cエリア25番出口に出る!')) 일반적으로 전각 -> 반각을 하고싶은 경우, unicodedata.nomalize를 사용하면 된다. 2. 전각 -> 반각 (문자열 범위 및 maketrans 이용) def full_to_half(text): table = str.maketrans({chr(0xFF01 + i): chr(0x21 + i) for i in range(94)}) return text.translate(table) print(full_to_half('Cエリア25..

python snippets

Python으로 Google Sheets에 있는 csv 사용하기

외부 라이브러리를 사용하지 않는 것을 기준으로 작성 이런 형태의 csv파일이 있다고 가정한다. 링크는 https://docs.google.com/spreadsheets/d/1TeL3R5cmkSGt-Ynn9bmuF05n00W-ufONOaEGFV9uMw4/edit#gid=883734849 기본작업 우선 권한을 '링크가 있는 모든 사용자'로 업데이트한다. 이래야 링크를 통한 접근이 가능해진다. 그다음, csv로 저장할지 바로 사용할지에 따라 방법이 갈린다. 1) 데이터를 csv 파일로 저장하여 사용하기 import urllib.request import csv doc_id = "1TeL3R5cmkSGt-Ynn9bmuF05n00W-ufONOaEGFV9uMw4" sheet_id = "883734849" url =..

python snippets

Python으로 ix.io에 데이터 올리기

import requests with open("test.json", "r", encoding="utf-8") as f: data = f.read() req = requests.post("http://ix.io", files={"f:1": data}) print(f"json 테스트: {req.content.decode('utf-8').strip()}") strdata = "테스트 데이터입니다." req = requests.post("http://ix.io", files={"f:1": strdata}) print(f"일반 텍스트 테스트: {req.content.decode('utf-8').strip()}") 출력: >>> json 테스트: http://ix.io/4bU0 >>> 일반 텍스트 테스트: htt..

Snowyegret
'python snippets' 카테고리의 글 목록