- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
import sys;
class Cout(object):
def __lshift__(self, anything):
sys.stdout.write(str(anything));
return self;
cout = Cout();
endl = '\n';
cout << 'Hello, World!' << endl;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−119
import sys;
class Cout(object):
def __lshift__(self, anything):
sys.stdout.write(str(anything));
return self;
cout = Cout();
endl = '\n';
cout << 'Hello, World!' << endl;
http://lurkmore.to/Обсуждение:Python#.D0.92_.D1.81.D1.82.D0 .B8.D0.BB.D0.B5_.D0.BF.D0.BB.D1.8E.D1.81 .D0.BE.D0.B2
−102
def booleanize(value):
"""Return value as a boolean."""
true_values = ("yes", "true", "1")
false_values = ("no", "false", "0")
if isinstance(value, bool):
return value
if value.lower() in true_values:
return True
elif value.lower() in false_values:
return False
В комментариях не нуждается.
−101
class ImageAsset(Asset):
def to_xml(self):
if self.asset_type == self.VIDEO:
return self.videoasset.to_xml()
element = etree.Element("imageAsset")
if self.mask_key:
element.set("maskId", self.mask_key)
if self.image_x:
element.set("imageX", str(self.image_x))
if self.image_y:
element.set("imageY", str(self.image_y))
if self.image_width:
element.set("imageWidth", str(self.image_width))
if self.image_height:
element.set("imageHeight", str(self.image_height))
self.set_xml_attrs(element)
return element
class VideoAsset(ImageAsset):
def to_xml(self):
element = etree.Element("videoAsset")
if self.mask_key:
element.set("maskId", self.mask_key)
if self.image_x:
element.set("imageX", str(self.image_x))
if self.image_y:
element.set("imageY", str(self.image_y))
if self.image_width:
element.set("imageWidth", str(self.image_width))
if self.image_height:
element.set("imageHeight", str(self.image_height))
self.set_xml_attrs(element)
return element
Полиморфизм это вам не шубу в трусы заправлять!
−88
class DataModel(dict):
_SCHEME_VERSION = 0
_transform = dict()
_additional = dict()
_migration = None
def __init__(self, data=None, network=None, conf=None):
if network and conf:
_scheme = map(lambda x: x.strip(), conf.get(network).keys())
_map = map(lambda x: x.strip(), conf.get(network).values())
self._scheme = int(conf._scheme)
map(lambda x: setattr(self, x[0], data.get(x[1], None)),
[(_scheme[i], _map[i]) for i in xrange(0,len(_map))])
if self._transform.get(network, False):
map(lambda x: setattr(self, x, getattr(self._transform[network], x)(getattr(self, x))),
[k for k in self._transform[network].__dict__.keys() if not k.startswith('__')])
else:
dict.__init__(self, data)
if self.get('_scheme', 0)<self._SCHEME_VERSION and self._migration is not None:
k = [int(k.split('_')[1]) for k in self._migration.__dict__.keys() if not k.startswith('__')]
k.sort()
[k.remove(x) for x in k if x<=self.get('_scheme', 0)]
map(lambda x: getattr(self._migration, 'scheme_%s' % x)(self), k)
self._scheme = self._SCHEME_VERSION
map(lambda x: setattr(self, x, getattr(self._additional, x)(self)),
[k for k in self._additional.__dict__.keys() if not k.startswith('__')])
def __setattr__(self, name, val):
if name in self.__dict__:
self.__dict__[name]= val
else:
self[name] = val
def __getattr__(self, name):
if name in self.__dict__:
return self.__dict__[name]
else:
return self[name]
Mongo migration, written in Python, for human beings.
−89
def mayakovsky(string):
splitted = string.split('\n')
l = [splitted[0]]
lastSpaces = 0
for i in range(1, len(splitted)):
l += [' '*(lastSpaces + len(splitted[i - 1]) + 1) + splitted[i]]
lastSpaces += len(splitted[i - 1]) + 1
return '\n'.join(l)
Лол.
−102
def _registerCommands(self, mapping=None, dataMapping=None, commandUpdates=None, dataUpdates=None):
...
for (cmdName, cmdClass) in cMap.iteritems():
...
self._setCommand(cmdObj)
def _setCommand(self, cmdObj):
if cmdObj.__class__.__name__.find("_") != -1:
name = unicode(cmdObj.__class__.__name__.split("_", 1)[1])
else:
name = unicode(cmdObj.__class__.__name__).lower()
setattr(self, name.lower(), cmdObj)
...
Fedora, pykickstart. Посоны регистрируют команды в парсере...
−94
list(zip_longest(*[iter(('0'+str(bin(int(time.time())))[2:]).replace('0', '_').replace('1', '*'))]*4))
увидел у в скрипте на подобии archey3
−422
import math
print math.pow(2,64) //1.84467440737e+19
print pow(2,64) //18446744073709551616
print 2**64 //18446744073709551616
http://ideone.com/kmGrBa
http://ideone.com/otSgCP
Говно в обоих версиях калькулятора.
−97
def load_library():
requests = []
class Handler(object):
pass
Handler.errors = 0
def handler(request):
print "failed to load: %s" % request.url
Handler.errors += 1
for node in res:
for url in filter(lambda x: x, map(node.prop, names)):
requests.append(grequests.get(url))
gmap(tuple(requests), exception_handler = handler)
print "total failures: %s" % Handler.errors
Ля-ля-ля, замыкания!
−96
import random
while 0<1:
inn_d=str(random.randint(100000000,999999999))
a=int(inn_d[:1])*2
b=int(inn_d[1:2])*4
c=int(inn_d[2:3])*10
d=int(inn_d[3:4])*3
e=int(inn_d[4:5])*5
f=int(inn_d[5:6])*9
g=int(inn_d[6:7])*4
l=int(inn_d[7:8])*6
m=int(inn_d[8:9])*8
x=a+b+c+d+e+f+g+l+m
y=x%11
if y%11==10:
y=0
print str(inn_d)+str(y)
Такой вот генератор ИННов