- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
def chicken():
print("Курица")
return egg()
def egg():
print("Яйцо")
return chicken()
try:
chicken()
except RecursionError:
print("ТЫ ПИДОР")
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−2
def chicken():
print("Курица")
return egg()
def egg():
print("Яйцо")
return chicken()
try:
chicken()
except RecursionError:
print("ТЫ ПИДОР")
−2
assert exec("from my_runtime_analyze_lib import do_amazing_magic") or True
if __name__ == '__main__':
do_smth()
assert do_amazing_magic()
do_smth_else()
Как вхерачить в код любую ересь для dev окружения, а потом отключить на продакшене. Только не забыть бы на проде при запуске флаг оптимизации.
+2
Pyhton 2:
>>> (2**54/1) + 10 - 10 == 2**54
True
>>> (2**64/1) + 10 == 2**64
False
Pyhton 3:
>>> (2**54/1) + 10 - 10 == 2**54
False
>>> (2**64/1) + 10 == 2**64
True
Pyhton 2: https://ideone.com/iqwl8L
Pyhton 3: https://ideone.com/ltG9Fq
Ну охуеть теперь.
x + 10 - 10 != x в общем случае - это норма?
Я всё понимаю - тяжёлое детство, инты, прибитые к железу, но на кой чёрт в современных интерпретируемых языках такое говнище?
+1
OrderedDict().fromkeys(['key1', 'key2', 'key3'], [])
Снова сел на грабли с изменяемыми объектами
+1
def ajax_check_manager_promocode(promocode, type_license):
if (not promocode):
return False
if (promocode is None):
return False
if (promocode.isdigit()):
return False
if (len(promocode) < 8):
return False
0
def normalize_phone(phone):
if (not phone):
return
normalized_phone = phone.replace("(", "").replace(")", "").replace("+", "").replace("-", "").replace(" ", "")
if normalized_phone[0] == "7":
p = list(normalized_phone)
p[0] = "8"
normalized_phone = "".join(p)
if normalized_phone[0] == "9":
normalized_phone = "8" + normalized_phone
return normalized_phone
Питонокод пхпешника.
0
Рубрика "плагины к Kodi" вернулась!
http://kodi-addons.club/addon/plugin.video.viks.tv/4.2.0
Качаем, открываем epg.db (формат sqlite), охуеваем. Можно еще поизучать файлы напитоне.
0
def _get_list(self, string):
"""
response to list parser, removes CSV list headers
"""
def f(x):
return x != '' and \
x != 'Created,e-Voucher number,Activation code,Currency,Batch,Payer Account,Payee Account,Activated,Amount' and \
x != 'Time,Type,Batch,Currency,Amount,Fee,Payer Account,Payee Account,Payment ID,Memo'
if not string:
return []
rlist = string.split('\n')
return filter(f, rlist)
https://perfectmoney.is/acct/samples/python/class.txt
Класс для работы с платёжным API
0
import re
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
text = input('Enter your message: ')
text = re.findall(r'\w', text)
key = input('Enter your key: ')
key = int(key)
a = len(text)
b = 0
num = 0
message = []
c = ''
for i in range(a):
num = alphabet.index(text[b])
num = num + key
b = b + 1
if num <= 25:
message.append(alphabet[num])
else:
num = num%25 - 1
message.append(alphabet[num])
print(text)
print(message)
for i in range(a):
c += message[(i)]
print(c)
Шифр Цезаря
0
import tkinter
import random
# constants
WIDTH = 540
HEIGHT = 480
BG_COLOR = 'white'
MAIN_BALL_COLOR = 'blue'
MAIN_BALL_RADIUS = 25
COLORS = ['aqua', 'fuchsia', 'pink', 'yellow', 'gold', 'chartreuse']
NUM_OF_BALLS = 9
MAX_RADIUS = 35
MIN_RADIUS = 15
DELAY = 8
INIT_DX = 1
INIT_DY = 1
ZERO = 0
# ball class
class Ball():
def __init__(self, x, y, r, color, dx=0, dy=0):
self.x = x
self.y = y
self.r = r
self.color = color
self.dx = dx
self.dy = dy
def draw(self):
canvas.create_oval(self.x - self.r, self.y - self.r, self.x + self.r, self.y + self.r, fill=self.color,
outline=self.color)
def hide(self):
canvas.create_oval(self.x - self.r, self.y - self.r, self.x + self.r, self.y + self.r, fill=BG_COLOR,
outline=BG_COLOR)
def is_collision(self, ball):
a = abs(self.x + self.dx - ball.x)
b = abs(self.y + self.dy - ball.y)
return (a * a + b * b) ** 0.5 <= self.r + ball.r
def move(self):
# collision with the walls
if (self.x + self.r + self.dx >= WIDTH) or (self.x - self.r + self.dx <= ZERO):
self.dx = -self.dx
if (self.y + self.r + self.dy >= HEIGHT) or (self.y - self.r + self.dy <= ZERO):
self.dy = -self.dy
self.hide()
self.x += self.dx
self.y += self.dy
if self.dx * self.dy != 0:
self.draw()
# process the mouse events
def mouse_click(event):
global main_ball
if event.num == 1: # left mouse button
if 'main_ball' not in globals(): # старт
main_ball = Ball(event.x, event.y, MAIN_BALL_RADIUS, MAIN_BALL_COLOR, INIT_DX, INIT_DY)
if main_ball.x > WIDTH / 2:
main_ball.dx = -main_ball.dx
if main_ball.y > HEIGHT / 2:
main_ball.dy = -main_ball.dy
main_ball.draw()
# create a list of objects-balls
def create_list_of_balls(number):
lst = []
return lst
# games main loop
def main():
if 'main_ball' in globals():
main_ball.move()
root.after(DELAY, main)
# create a window, the canvas and start game
root = tkinter.Tk()
root.title("Colliding Balls")
canvas = tkinter.Canvas(root, width=WIDTH, height=HEIGHT, bg=BG_COLOR)
canvas.pack()
canvas.bind('<Button-1>', mouse_click)
canvas.bind('<Button-2>', mouse_click, '+')
canvas.bind('<Button-3>', mouse_click, '+')
balls = create_list_of_balls(NUM_OF_BALLS)
if 'main_ball' in globals(): # for restarts
del main_ball
main()
root.mainloop()