봉 블로그

python tip 본문

Python

python tip

idkbj 2014. 11. 11. 09:25


# script 파일을 업로드하고 mode 변경후 실행하기 (fabric 사용)

    put(open(mainDir + '/commands.txt'), 'commands.sh', mode=0755)

    result = run('./commands.sh', pty=False, combine_stderr=True)


# json 파일 pretty print

    python -m json.tool ./core/spidercore/vms.json

    logger.debug(json.dumps(nics, indent=4))


#파일 앞뒤 2줄씩 삭제하고 리턴

    list = file_contents.split('\n')

    return "\n".join(list[2: len(list)-2])


#good logging practice in python

http://victorlin.me/posts/2012/08/26/good-logging-practice-in-python


#__init__.py의 용도 (기초)

https://wikidocs.net/1418


# Exception Hierarchy

https://docs.python.org/3/library/exceptions.html#exception-hierarchy


# Manually rase Exception

http://stackoverflow.com/questions/2052390/how-do-i-manually-throw-raise-an-exception-in-python