- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
import string
k=input()
a=range(1000)
if k==1:
a[0]=input()
else:
t = string.replace(str(raw_input()), ' ', ', ')
a=eval('('+t+')')
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−97
import string
k=input()
a=range(1000)
if k==1:
a[0]=input()
else:
t = string.replace(str(raw_input()), ' ', ', ')
a=eval('('+t+')')
4
2 3 4 5
----
Не знаю я питон :(
По другому не смог быстро написать..
−173
fout = open("number23.out", "w")
fin = open("number23.in", "r")
N = int(fin.read())
secret = 6
key = 9
system = 10
Magic23 = 23
magic1 = magic2 = 0
if(N < Magic23//2):
N = Magic23//2
for j in range(0, Magic23//2 + (Magic23 - 1)*((N - Magic23//2)//(Magic23-1)) - 1, 2):
magic1 *= system
magic1 += key - secret
magic1 *= system
magic1 += secret
magic2 *= system
magic2 += key - (system - secret)
magic2 *= system
magic2 += system - secret
magic1 *= system
magic1 += system - secret
magic2 *= system
magic2 += secret
if(N % 2):
power = str(magic1 ** 2)
fout.write(power[len(power)//2:])
else:
power = str(magic2 ** 2)
fout.write(power[len(power)//2:])
fout.close()
fin.close()
нужно было найти число длины от N до N + 23, такое, чтобы удвоенная его запись была полным квадратом натурального числа) Оценивайте) Приятного говноосмотра)
−172
time.strftime('%Y/%m/%d', time.localtime(time.time()+86400))
Вычисление завтрашней даты.
В день перехода на зимнее время этот код не будет работать.
До сих пор не знаю, как это сделать правильно.
−91
import sys
from ru.hastel.gameserver.model.quest import State
from ru.hastel.gameserver.model.quest import QuestState
from ru.hastel.gameserver.model.quest.jython import QuestJython as JQuest
qn = "2008_christmas"
class Quest (JQuest) :
def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
def onEvent (self,event,st) :
htmltext = event
if event == "1":
if st.getQuestItemsCount(5556) >= 4 and st.getQuestItemsCount(5557) >= 4 and st.getQuestItemsCount(5558) >= 10 and st.getQuestItemsCount(5559) >= 1:
st.takeItems(5556,4)
st.takeItems(5557,4)
st.takeItems(5558,10)
st.takeItems(5559,1)
st.giveItems(5560,1)
htmltext = "<html><body>Merry Christmas.</body></html>"
else:
htmltext = "31863-2.htm"
elif event == "2":
if st.getQuestItemsCount(5560) >= 10 :
st.takeItems(5560,10)
st.giveItems(5561,1)
htmltext = "<html><body>Merry Christmas.</body></html>"
else:
htmltext = "31863-3.htm"
if htmltext != event:
st.setState(COMPLETED)
st.exitQuest(1)
return htmltext
def onTalk (self,npc,player):
st = player.getQuestState(qn)
if not st : return
npcId = npc.getNpcId()
if npcId == 31863 :
htmltext = "31863-1.htm"
st.setState(STARTED)
return htmltext
QUEST = Quest(2008,qn,"custom")
CREATED = State('Start', QUEST)
STARTED = State('Started', QUEST)
COMPLETED = State('Completed', QUEST)
QUEST.setInitialState(CREATED)
QUEST.addStartNpc(31863)
QUEST.addTalkId(31863)
Вот простенький эвент на Питоне , как улучшить подскажите
−172
from django.conf.urls.defaults import *
from django.contrib.auth.views import logout_then_login
from django.shortcuts import redirect
from forms import LogoutForm
urlpatterns = patterns('',
(r'^logout/$', lambda r: (
r.method == 'POST' and
LogoutForm(r.POST).is_valid() and
logout_then_login(r) or
redirect('index')
), {}, 'logout'),
)
Про Django.
Только не бейте сильно;) Ну, лень мне было для этого отдельный view делать...
−179
class Source:
id = ''
values = []
arrays =[ ( 'bool_array', bool), ( 'float_array', float), ('IDREF_array', str), ('int_array', int), ('Name_array', str), ('SIDREF_array', str), ('token_array', str)]
def __init__(self, node):
self.id = node.getAttribute('id')
accessors = dict([ (accessor.getAttribute('source')[1:], (int(accessor.getAttribute('count')), int(accessor.getAttribute('stride'))) ) for technique in node.getElementsByTagName("technique_common") for accessor in technique.getElementsByTagName("accessor") ])
values = [(arrayNode.getAttribute('id'), int(arrayNode.getAttribute('count')), [array[1](v) for v in getText(arrayNode).split()]) for array in Mesh.Source.arrays for arrayNode in node.getElementsByTagName(array[0])]
self.values = [ array[2][i*accessors[array[0]][1]:(i+1)*accessors[array[0]][1]] for array in values for i in range(accessors[array[0]][0])]
<source id="Box001-lib-Position">
<float_array id="Box001-lib-Position-array" count="24">-23.296745 -46.390999 0.000000 23.296745 -46.390999 0.000000 -23.296745 46.390999 0.000000 23.296745 46.390999 0.000000 -23.296745 -46.390999 35.287621 23.296745 -46.390999 35.287621 -23.296745 46.390999 35.287621 23.296745 46.390999 35.287621</float_array>
<technique_common>
<accessor source="#Box001-lib-Position-array" count="8" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
в результате нужно получить список в виде
[[-23.296745, -46.390999, 0.0], [23.296745, -46.390999, 0.0], [-23.296745, 46.390999, 0.0], [23.296745, 46.390999, 0.0], [-23.296745, -46.390999, 35.287621], [23.296745, -46.390999, 35.287621], [-23.296745, 46.390999, 35.287621], [23.296745, 46.390999, 35.287621]]
Неделю назад начал учить питон, и для того чтоб это было совсем полезно, решил попробовать написать на нем парсер Collada файлов.
Очень сильно проникся идеей инициализации массивов, из-за чего и родился сей говнокод...
Код выдает правильный результат, но абсолютно не читаемый...
−167
if abs(self.__last_direction%360-direction.angle())==270:
angle = 360*(self.__last_direction/360+1)+direction.angle()
else:
angle = 360*(self.__last_direction/360) + direction.angle()
крутим крутим спрайт
−166
import cgi
import MySQLdb
MyDB=MySQLdb.connect(host='localhost', user='root', passwd='', db='serv')
cursor=MyDB.cursor()
cursor.execute("""SELECT * FROM IndexPage WHERE id=2""")
zg1=cursor.fetchall()
zp=cgi.FieldStorage()
p=zp.has_key('pages')
lixt='lrof'
title='{TITLE}'
Block1='{BLOCK_1}'
if p==1:
print 'Content-Type: text/html\n'
sh=open(r'themplates/sh2')
res=sh.read()
...
Пхпшники пересаживаются на Питон
−181
function hilight { python2 -c 'import sys, re; map(lambda s: sys.stdout.write(re.sub(r"'$1'", lambda m: "\033[1;31m%s\033[0m" % m.group(0), s)), sys.stdin)' }
Это в Python или в bash?
−171
ms = decode_mail_headers(decodeUnknown(message.get_charset(), message.get('Subject', 'Created from e-mail'))).replace("Re: ", "").replace("Fwd: ","").replace("Fw: ", "").rep lace("RE: ", "").replace("FW: ", "").strip()
Веселые программисты не знают регэкспов в питоне.