Post

(python) 팁, 메모

hidden-features-of-python

설정값 (config file. properties, json, yml) 관리하기

https://mingrammer.com/ways-to-manage-the-configuration-in-python/

editable로 설치
1
2
3
4
pip install --editable .
-e, --editable <path/url>
Install a project in editable mode (i.e. setuptools develop mode) from a local project path or a VCS url.

패키지 수동 설치

패키지 압축을 해제하고 dist(distribution) 폴더로 이동해서 다시 tar 압축 해제 반드시 해당 폴더에서 진행할 것.

1
2
python setup install

CLI에서 쓸만한 라이브러리
paramiko(docs)

python으로 SSH를 사용할 수 있는 모듈. server, client 모두 지원한다. 아나콘다에 기본적으로 포함되어 있는 pexpect 라는 모듈도 있다. 둘 중 어느게 더 좋은지는 모르겠음. pexpect의 경우 프롬프트를 자동으로 인식하는 등 약간 휴리스틱이 들어가 있는 듯?

2to3 -w aaa.py
1
2
3
4
λ 2to3 -w UCT.py
λ ls
UCT.py  UCT.py.bak

python2로 작성된 파일을 3으로 수정하려면 2to3 모듈을 사용한다. -w옵션을 주면 자동으로 백업파일 생성하면서 3로 변경해준다. 변경 이후 발생하는 에러는 대부분 문자열, 바이트 인코딩 관련 오류이므로, b' '또는 .python encode() 메소드 등으로 적절히 해결한다.

Evaluation strategy

파이썬은call by object reference 다. immutable object를 넘길 경우 ( 정수나, 정수를 참조하는 변수 ) call by value처럼 동작한다. mutable object를 넘길 경우 (리스트 등) call by reference처럼 동작한다.

This post is licensed under CC BY 4.0 by the author.