1. Python / Говнокод #7545

    −89

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    #weather.pyw
    
    from urllib import request
    from tkinter import *
    import tkinter
    import threading
    from threading import *
    import time
    
    i = 0
    active = True
    
    def timerTick( toSleep ):
      global active
      while active:
        refreshCall(0)
        time.sleep(toSleep)
    
    
    def refreshCall(event):
      t = Thread(target = refresh)
      t.start()
    
    def refresh(*event):
      global i
      ref['text'] = str(i)
      i+=1
      r = request
      page = str(r.urlopen('http://realmeteo.ru/moscow/1/current/').read())
      temperature = page.split('</tr><tr id="num_data"><td>')[1].split(' ')[0]
      pressure = page.split('                    </td><td>')[1].split(' ')[0]
      wind = page.split('<tr id="num_data"><td></td><td>')[1].split(' ')[0]
      dest = page.split('<param name="movie" value="/.swf/wind_dir/')[1].split('.swf')[0]
      destination = ''
      for c in dest:
        if c is dest[-1]:
          destination += {'N':'Север','S':'Юг','W':'Запад','E':'Восток'}[c]
        else:
          destination += {'N':'Северо-','S':'Юго-','W':'Западо-','E':'Востоко-'}[c]
      #print( temperature, pressure, wind, destination )
      l1['text'] = 'Температура: '+temperature
      l2['text'] = 'Давление   : '+pressure
      l3['text'] = 'Сила ветра : '+wind
      l4['text'] = 'Направление: '+destination
    
    r = request
    page = str(r.urlopen('http://realmeteo.ru/moscow/1/current/').read())
    temperature = page.split('</tr><tr id="num_data"><td>')[1].split(' ')[0]
    pressure = page.split('                    </td><td>')[1].split(' ')[0]
    wind = page.split('<tr id="num_data"><td></td><td>')[1].split(' ')[0]
    dest = page.split('<param name="movie" value="/.swf/wind_dir/')[1].split('.swf')[0]
    destination = ''
    for c in dest:
      if c is dest[-1]:
        destination += {'N':'Север','S':'Юг','W':'Запад','E':'Восток'}[c]
      else:
        destination += {'N':'Северо-','S':'Юго-','W':'Западо-','E':'Востоко-'}[c]
    
    
    form = tkinter.Tk()
    l1 = Label(form,text='Температура: '+temperature,justify='left'); l1.pack()
    l2 = Label(form,text='Давление   : '+pressure,justify='left'); l2.pack()
    l3 = Label(form,text='Сила ветра : '+wind,justify='left'); l3.pack()
    l4 = Label(form,text='Направление: '+destination,justify='left'); l4.pack()
    ref = Button(form, text = 'Обновить'); ref.pack()
    
    ref.bind('<Button-1>',refreshCall)
    
    timerThread = Thread(target = timerTick, args=(5,))
    
    timerThread.start()
    
    form.mainloop()
    
    active = False

    Угадайте, с какого языка пересел автор. (не пэхапэ)

    Fai, 15 Августа 2011

    Комментарии (33)
  2. Python / Говнокод #7544

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    # разбираюсь с питоном, может растолкуете почему так
    >>> z = [lambda: i for i in [1,2,3]]
    # почему вот такой результат?
    >>> z[0](), z[1](), z[2]()
    (3, 3, 3) 
    
    # каждый элемент списка - отдельная функция
    >>> z[0] == z[1], z[0] is z[1]
    (False, False)
    
    # вот таким образом выходит правильно.
    >>> z = [lambda: 1, lambda: 2, lambda:3]
    >>> z[0](), z[1](), z[2]()
    (1, 2, 3)

    Автор - я. Меня действительно интересует, почему так происходит.

    Fai, 14 Августа 2011

    Комментарии (14)
  3. Python / Говнокод #7541

    −175

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if request.path == '/':
            thread_list = ThreadBlock.objects.all()
        else:
            thread_nomer = re.search( r'/\d*/', request.path ).group()[1:-1]
            thread_list = ThreadBlock.objects.filter(id=int(thread_nomer))

    Бидон, джанга, уеб.

    хуита, 14 Августа 2011

    Комментарии (3)
  4. Python / Говнокод #7540

    −88

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    # -*- coding: utf-8 -*-
    from Tkinter import *
    import time
    import random
    import os
    def init(): #Инициалиазия, переменная root, задаём размеры окна
    	global root, widthmin, widthmax, heightmin, heightmax, geometry
    	widthmin = 400 
    	widthmax = 400
    	heightmin = 400
    	heightmax = 400
    	geometry = str(widthmax) + 'x' + str(heightmax)
    	root = Tk()
    	root.geometry(geometry)
    	root.minsize(width=widthmin,height=heightmin)
    	root.maxsize(width=widthmax,height=heightmax)
    	menu()
    	root.mainloop()
            
    def menu(): #Меню игры. С любовью, кэп
    	global btSingle, btMulti, btSetting, btQuit
    	btSingle = Button(root, text="Singleplayer", command=singleplayer)
    	btSingle.pack(padx=15,pady=15)
    	btMulti = Button(root, text="Multiplayer", command=multiplayer)
    	btMulti.pack(padx=15,pady=15)
    	btSettings = Button(root, text="Settings", command=settings)
    	btSettings.pack(padx=15,pady=15)
    	btQuit = Button(root, text="Quit", command=quit)
    	btQuit.pack(padx=15,pady=15)
    	
    
    def singleplayer(): #Функции синглплеера
        global root #Удалить после заполнения функции более полезной хренью
    
    def multiplayer(): #Функции мультплеера
    	global root #Удалить после заполнения функции более полезной хренью
    
    def settings(): #Настройки
    	global root #Удалить после заполнения функции более полезной хренью
    	
    def quit(): #Выход из игры
    	root.destroy ()
    
    init()

    Burst_in, 13 Августа 2011

    Комментарии (6)
  5. Python / Говнокод #7531

    −90

    1. 1
    2. 2
    def delay():
        return random.randrange(0,20)+20

    Pyhpon, 12 Августа 2011

    Комментарии (2)
  6. Python / Говнокод #7519

    −92

    1. 1
    2. 2
    intToStr = { x:'%s'%x for x in range(-1000, 1000) }
    intToStr[-543]   # <- '-543'

    ЭТО ПИТОН!!!

    Fai, 11 Августа 2011

    Комментарии (6)
  7. Python / Говнокод #7506

    −86

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    def MonthsListGen(*args, **kwargs):
    	from datetime import datetime
    
    	if kwargs.has_key('month') and kwargs.has_key('year'):
    		return "%s-%s"%(kwargs['year'], "0%d"%kwargs['month'] if kwargs['month']<10 else str(kwargs['month']))
    
    	if kwargs.has_key('date'): return MonthsListGen(year = kwargs['date'].year, month = kwargs['date'].month)
    
    	if kwargs.has_key('decodeName'): return MONTH_NAMES[int(kwargs['decodeName'].split('-')[1])]
    	if kwargs.has_key('decodeYear'): return int(kwargs['decodeYear'].split('-')[0])
    	if kwargs.has_key('startDate') and kwargs.has_key('endDate'):
    		startDate = kwargs['startDate']
    		endDate = kwargs['endDate']
    		monthList = []
    		if startDate.year < endDate.year:
    			startDate1 = startDate
    			endDate1 = datetime.strptime('%d.%d.%d'%(DAYS_IN_MONTH[12], 12, startDate1.year) , '%d.%m.%Y')
    			monthList = MonthsListGen(startDate = startDate1, endDate = endDate1)
    
    			startDate2 = datetime.strptime('%d.%d.%d'%(1, 1, startDate1.year+1) , '%d.%m.%Y')
    			endDate2 = endDate
    			monthList += MonthsListGen(startDate = startDate2, endDate = endDate2)
    			return monthList
    		if startDate.year == endDate.year:
    			monthRange = range(startDate.month, endDate.month+1)
    			year = startDate.year
    			for monthNo in monthRange:
    				monthList.append(MonthsListGen(year = year, month = monthNo))
    			return monthList
    	return False

    Вместо того, чтобы писать несколько разных функций, решил сделать одну, которая почти во всех случаях вызывает сама себя с разными параметрами.

    hakimovis, 10 Августа 2011

    Комментарии (13)
  8. Python / Говнокод #7502

    −184

    1. 1
    2. 2
    3. 3
    s="ftmbG!>!fvsU";k=''
    for i in s:k+=map(lambda x:chr(ord(x)-1),s)[s.index(i)]
    exec(k[::-1])

    "Счастливой отладки, суки!" (с)

    TheHamstertamer, 09 Августа 2011

    Комментарии (36)
  9. Python / Говнокод #7487

    −415

    1. 1
    pygame.mouse.set_cursor((16, 19), (0, 0), (128, 0, 192, 0, 160, 0, 144, 0, 136, 0, 132, 0, 130, 0, 129, 0, 128, 128, 128, 64, 128, 32, 128, 16, 129, 240, 137, 0, 148, 128, 164, 128, 194, 64, 2, 64, 1, 128), (128, 0, 192, 0, 224, 0, 240, 0, 248, 0, 252, 0, 254, 0, 255, 0, 255, 128, 255, 192, 255, 224, 255, 240, 255, 240, 255, 0, 247, 128, 231, 128, 195, 192, 3, 192, 1, 128))#костыль))

    Разгребал сорцы одной совей древней программки, нашел это.
    ЗЫ: комент таким и был

    TheHamstertamer, 08 Августа 2011

    Комментарии (101)
  10. Python / Говнокод #7467

    −99

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    T, b= 0, []
    While t!=10:
      If t!=6:
        Print ''Чётные числа''
        A = int(raw_input('>> '))
        B.append(a)
      If t!=500:
        Print 'не чётные'
        А = int(raw_input('>> '))
        B.append(a)
    
    #якобы условия для того чтоб ввод был как бы зеброй, четные, не чётные#

    KATAJIU3ATOP, 06 Августа 2011

    Комментарии (6)