JSON은 정보나 객체를 전달하기 위한 표준으로, RFC 7159와 ECMA-404에 명세되어 있다.
파이썬은
- 표준라이브러리 차원에서 강력한 JSON 컨버터 제공
- 파이썬 타입과 JSON타입의 유사성
이라는 장점이 있어 쉽게 JSON과 친해질 수 있다.
RewriteEngine On | |
RewriteBase / | |
RewriteCond %{REQUEST_FILENAME} -s [OR] | |
RewriteCond %{REQUEST_FILENAME} -l [OR] | |
RewriteCond %{REQUEST_FILENAME} -d | |
RewriteRule ^.+$ - [NC,L] | |
RewriteCond %{REQUEST_METHOD} (PUT|DELETE) | |
RewriteRule .* put.php |
How about recursion? that makes it simple. for example, | |
**generators.py** | |
``` | |
def gen_arrayfield(base_field, size, generate_value): | |
array = [] | |
for _ in range(size): | |
array.append(generate_value(base_field)) | |
return array | |
gen_arrayfield.required = ['base', 'size'] |
class UserManager(BaseUserManager): | |
def create_user(self, username, password=None): | |
""" | |
Creates and saves a User with the given username and password | |
""" | |
if not username: | |
raise ValueError('Users must have an email address') | |
user = self.model( | |
username=username, |
@api_view(['GET', 'POST']) | |
def login_facebook(request): | |
""" | |
login via facebook | |
PREREQUISITES: getting 'code' at frontend using oauth uri like this: | |
https://www.facebook.com/dialog/oauth?client_id=563193193877116&response_type=code&scope=user_friends,public_profile,email&redirect_uri=http://api.phople.us/login_facebook | |
:param request: request | |
:return: login result |
def sendmail(recipients, anime, content): | |
""" | |
Send email to recipients | |
:param recipients: recipients | |
:param anime: animation info | |
:param content: io.StringIO object messages | |
:return: None | |
""" | |
if 1 == 1: # TODO Remove this dev option | |
return |
#Python zip archive of a directory
디렉토리를 .zip
파일로 압축하는 것은 자주 있는 일이다.
짧은 코드로 글을 정리한다. 참조
##무압축
방법은 zipfile, shutil 모듈을 사용한 방법으로 나뉜다. 결과는 같으나 편리함이 다르다.
#Python itertools 공식문서를 참조했다.
itertools는 반복 행위가 필요한 부분을 빠르고, 효율적으로 구현할 수 있도록 한다. operator
모듈과도 궁합이 좋다.
##Cheat Sheet
#Python argparse 공식 문서를 참조했다.
커맨드라인 인터페이스를 갖는 프로그램을 만들 때, 자주 사용되는 것은 역시나 command line arguments다. C에 optget()
이 있다면, Python은 argparse
가 있다.
자질구레한 작은 예제 말고 큰 예제로 한눈에 사용법을 익혀보자.
##Cheat Sheet