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 itertools import combinations | |
from math import factorial | |
def count_combinations(n: int, r: int): | |
return int(factorial(n) / (factorial(r) * factorial(n-r))) | |
team_count = 4 | |
# 0 1 2 3 4 5 6 7 8 9 10 11 |
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
{{ apple|default:lemon.dictattr.color }} {# VariableDoesNotExist exception 발생 #} | |
<hr /> | |
{% with lemon.dictattr.color as colour %} | |
{{ apple|default:colour }} {# 문제 없음 #} | |
{% endwith %} | |
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) |
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
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
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
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
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
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
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: |
NewerOlder