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

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de" dir="ltr">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    		<meta name="keywords" content="Kabel Deutschland, digitale Belegung, Frequenzen, Kanäle, Sender" />

    Вся страница тут https://helpdesk.kdgforum.de/sendb/belegung.html
    Ебучий lxml при попытке парсить документ в неправильной кодировке (Невалидный utf8, в meta name="keywords" содержимое в однобайтовой кодировке. Как такое получили - другой вопрос) тихо сваливается в какую-то однобайтовую кодировку. Браузер всё показывает нормально. Несмотря на xhtml, который вроде должен заставлять строго парсить.

    syoma, 01 Сентября 2018

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

    −2

    1. 1
    if type(colType) == type(0): # it's a length

    Библиотека csv, встроенная в питон.

    syoma, 01 Сентября 2018

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

    −1

    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
    import datetime
    import mysql.connector
    
    cnx = mysql.connector.connect(user='scott', database='employees')
    cursor = cnx.cursor()
    
    query = ("SELECT first_name, last_name, hire_date FROM employees "
             "WHERE hire_date BETWEEN %s AND %s")
    
    hire_start = datetime.date(1999, 1, 1)
    hire_end = datetime.date(1999, 12, 31)
    
    cursor.execute(query, (hire_start, hire_end))
    
    for (first_name, last_name, hire_date) in cursor:
      print("{}, {} was hired on {:%d %b %Y}".format(
        last_name, first_name, hire_date))
    
    cursor.close()
    cnx.close()

    Как выглядит mysql_real_escape_string в Python?

    real_escape_string, 31 Августа 2018

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

    −2

    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
    def printlen(x):
        print(len(x))
    
    def argslist(x):
        return list(x.args)
    
    def add(value_error, arg):
        raise Exception(*value_error, *arg)
    
    def fibonacci(a, b, x):
        try:
            assert b<x
            printlen(b)
            try:
                add(a,b)
            except Exception as e:
                fibonacci(argslist(e), a, x)
        except AssertionError as e:
            print(e)
    
    threshold = 1000
    fibonacci([[]],[[]],[[]]*threshold)

    Выводит числа Фибоначчи от 1 до threshold.
    Если убрать строку "assert b<x", то python.exe займёт всю оперативку, потому что зачем лимит вложенности исключений?

    tungmetla, 30 Августа 2018

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

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    def spam(low, up):
        for eggs in range(low, up+1):
            if str(eggs) in str(eggs**2):
                print(str(eggs) + " is in " + str(eggs**2) + ".")

    Проверяет, есть ли стринг числа n в стринге числа n**2.

    shite, 29 Августа 2018

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

    −3

    1. 1
    Зачем нужен "z == int(str(z)[::-1])", если есть "int(str(z)[:len(str(z))//2]) == int(str(z)[int((len(str(z))+1)//2):][::-1])"?

    shite, 28 Августа 2018

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

    −4

    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
    stack = []
    
    def stdout(x):
        if x == "puts":
            print(stack.pop())
        else:
            raise Exception("иди нахуй")
    
    def stdin(x):
        global stack
        if x == "gets":
            stack.append(input())
        else:
            raise Exception("иди нахуй")
    
    math = {
        "add": lambda: stack.append(float(stack.pop()) + float(stack.pop())),
        "sub": lambda: stack.append((-float(stack.pop())) + float(stack.pop())),
        "mul": lambda: stack.append(float(stack.pop()) * float(stack.pop())),
        "div": lambda: stack.append(1 / float(stack.pop()) * float(stack.pop())),
    }
    
    def stack_commands(x):
        global stack
        if x == "swap":
            stack[-1], stack[-2] = stack[-2:]
        elif x == "drop":
            stack.pop()
        elif x == "dup":
            stack.append(stack[-1])
        else:
            raise Exception("иди нахуй")
    
    string = {
        "concat": lambda: stack.append(str(stack.pop()) + str(stack.pop()))
    }
    
    commands = {
        "comment": lambda x: x,
        "push": lambda x: stack.append(x),
        "stdout": stdout,
        "stdin": stdin,
        "math": lambda x: print(math[x]()),
        "stack": stack_commands,
        "string": lambda x: string[x]()
    }
    
    def do(x):
        if '@' not in x:
            raise Exception(x + " is not email.")
        a, b = x.split('@')
        b = b.split('.')[0]
        commands[b](a)
    
    def eval(s):
        for i in s.lower().split():
            do(i)
    
    eval("""
    [email protected]
    
    [email protected] [email protected]
    [email protected]
    [email protected] [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected] [email protected] [email protected]
    """)

    666_N33D135, 25 Августа 2018

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

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    def lookup(self, code):
            """
            Looks up code in Redis
            Returns None on failure
            """
            url = self.redis.get(code)
            try:
                pass
            except:
                url = None
            return url

    Вот такое на полном серьезе получили как кусочек домашнего задания для соискателя на Senior Python Engineer

    Flid, 16 Августа 2018

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

    −2

    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
    Помните я потешался над обитателями форума phpclub?
    Так вот у питонистов тоже есть такой форум, а там раздел "python для экспертов".
    
    Дай, думаю, зайду, послушаю о чем эксперты лалакают.
    Может быть обсуждают не выпилить-ли GIL из CPython?
    Или радуются появившимся в 3.7 датаклассам?
    
    А там:
    http://python.su/forum/topic/35652/
    http://python.su/forum/topic/35479/
    http://python.su/forum/topic/35575/
    http://python.su/forum/topic/35592/
    
    Такие вот нынче эксперты

    roskomgovno, 10 Августа 2018

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

    −1

    1. 1
    https://stackoverflow.com/questions/51521158/in-python-why-does-0xbin-return-false

    Свежий обосрамс питона

    syoma, 26 Июля 2018

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