This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# works on Python 3 | |
def check_argument_type(func): | |
def wrapper(*args): | |
if ( | |
not hasattr(func, '__annotations__') or | |
len(func.__annotations__) == 0 | |
): | |
return func(*args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
Point_type = namedtuple('Point', ('x', 'y')) | |
point_instance = Point_type(1, 10) | |
print(type(Point_type)) | |
print(type(point_instance)) | |
print(point_instance.__class__.__name__) | |
print(isinstance(point_instance, Point_type)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c_num = 10 | |
d_num = 0 | |
def do_something(a, b, c=0, d=0): | |
return a + b + c + d | |
if d_num > 0: | |
print(do_something(1, 2, c=c_num, d=d_num)) | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"shell_cmd": "python -u \"$file\"", | |
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", | |
"selector": "source.python", | |
"env": {"PYTHONIOENCODING": "utf8"} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LikeDict(dict): | |
def __getattribute__(self, attr): | |
return self[attr] | |
def __setattr__(self, attr, value): | |
self[attr] = value | |
class LikeDict2(object): | |
def __getitem__(self, key): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import QueryDict | |
from django.http.multipartparser import MultiValueDict | |
class MoreMethodsMiddleware(object): | |
def process_request(self, request): | |
method = request.META.get('REQUEST_METHOD', '').upper() | |
request.PUT = QueryDict('') | |
request.DELETE = QueryDict('') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from django.db import models | |
from django.utils import timezone | |
class Post(models.Model): | |
# created_at = models.DateTimeField(auto_now_add=True) # 원래 필드 | |
# updated_at = models.DateTimeField(auto_now=True) # 원래 필드 | |
# created_at = models.DateTimeField(default=datetime.now) # TIMEZONE 을 안 쓰는 경우 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Number(int): | |
def __add__(self, value): | |
return self.__int__() + value * 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseModel(models.Model): | |
class Meta: | |
abstract = True | |
class A(BaseModel): | |
pass | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
def hello(now=datetime.now()): | |
print(now) |
OlderNewer