목록Python (53)
준호씨의 블로그
python 에서 config 파일을 불러올 때 사용할 수 있는 기본 모듈은 configparser 입니다. (참고로 python 2 에서는 ConfigParser 이고 python 3 에서는 configparser 입니다.) 기본 내장 모듈이기 때문에 별도로 설치 해 줄 필요는 없습니다. 간단한 예제를 만들어 보기 위해 config.ini 파일을 만들어 봅니다. [DEFAULT] USERNAME = junho85 PASSWORD = 123456python 코드를 구현합니다. import configparser config = configparser.ConfigParser() config.read('config.ini') username = config['DEFAULT'][&..
python 에서 yaml 을 이용하는 간단한 방법은 pyyaml 모듈을 이용하는 방법입니다. 우선 pyyaml 모듈을 설치를 하려면 다음 커맨드를 이용하면 됩니다. pip install pyyaml그리고 yaml 파일을 하나 만들어 봅니다. 취향껏 만들어 주시면 됩니다. developer: - june - hello - worldyaml 문법에 대해 자세히 알고 싶으면 YAML 문서를 참고해 보시기 바랍니다. python 코드를 작성해 줍니다. import yaml with open('members.yaml') as file: members = yaml.load(file, Loader=yaml.FullLoader) print(members)open 으로 members.yaml 파일을 열어..
github 일일커밋 인증샷 자동화. python. selenium from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from PIL import Image from io import BytesIO driver = None try: driver = webdriver.Chrome('/Users/junho85/Downloads/chromedriver') driver.get("https://github.com/junho85") elem = driver.find_element_by_class_name("js-yearly-contributions") last_date_elem =..
Requests http://docs.python-requests.org/en/master/user/quickstart/ 사용자 편의성은 이게 제일 좋은 것 같다. 설치 $ pip install reuqests 사용 $ python >>> import requests >>> r = requests.get('https://api.github.com/events') >>> print(r.url) https://api.github.com/events >>> print(r.content) [{"id":"7687592113","type":"PushE... post, put, delete, head, options... >>> r = requests.post('http://httpbin.org/post', data..
https://gist.github.com/junho85/0d8c4beb0441bb0337914ca6e69dd915 과정 처음에는 fixed size list 를 사용할 방법을 찾아 보다가 deque 라는 녀석을 알게 되었다. (https://stackoverflow.com/a/16430458/964890) 새로운 값이 들어가면 자연스럽게 기존에 들어갔던 값이 제거 되니 딱 적절해 보였다. 처음에는 이렇게 짰는데 첫번째 테스트를 무사히 통과 했다. def solution(cacheSize, cities): answer = 0 q = deque(maxlen=cacheSize) for item in cities: if item in q: answer += 1 else: answer += 5 q.append(..