Fork me on GitHub

Other articles


  1. Datetime과 Timestamp

    Published: Fri 22 December 2017
    Updated: Fri 22 December 2017
    By Yunseop Song

    In python.

    Python에서 Datetime과 Timestamp를 사용할 때가 많은데 맨날 헷갈린다.

    보통 Datetime은 datetime 모듈을, Timestamp는 time 모듈을 사용한다.

    알아두면 편한 몇가지 방법

    일단 import 하자

    from datetime import datetime
    from time import time, mktime
    
    • String을 datetime으로 변환
    datetime.strptime('2017-12-25', '%Y-%m-%d')
    
    • datetime을 String으로 변환
    datetime.strptime('2017-12-25', '%Y-%m-%d …
    read more

    There are comments.

  2. nosetest와 coverage

    nosetest에는 기본적으로 coverage를 측정할 수 있는 기능이 있어서 몇가지 옵션만 추가로 넣어주면 바로 사용가능하다.

    일단 nose, coverage를 설치하자

    $ pip install nose
    $ pip install coverage
    $ nosetests --with-coverage --cover-package=app --cover-html --cover-html-dir=cover tests/test_coverage.py
    

    옵션에 대한 상세한 내용은 공식문서에서 확인할 수 있다.

    --with-coverage           테스트 시 coverage를 측정하겠다
    --cover-package           coverage를 …
    read more

    There are comments.

  3. contextlib

    Published: Wed 27 September 2017
    Updated: Thu 23 November 2017
    By Yunseop Song

    In python.

    Python에서 with라는 키워드를 사용하면뭔가의 시작과 끝을 제어할 수 있다.

    보통 파일을 열때 많이 쓰는데 다음과 같다.

    with open('test.txt', 'r') as txt:
        txt.read()
        ...
    

    이렇게 사용하면 txt라는 변수에 할당된 파일을 with 구문이 끝나면 자동으로 닫아준다.

    Pythoncontextlib을 사용하면 저것과 비슷한 역할을 하는 함수를 만들 수 …

    read more

    There are comments.

Page 1 / 3 »

links

social