• 11-12-2022, 14:12:02
    #1
    import random
    file_path = "xxx.txt"
    with open(file_path) as f:
        lines = f.readlines()
    random_line = random.choice(lines)
    print(random_line)
    bu kod ile xxx.txt üzerinden random bir satırı yazdırıyorum. yazdırdıktan sonra o veriyi txt üzerinden silmek istiyorum bunu nasıl yapabilirim?
  • 11-12-2022, 14:13:49
    #2
    ChatGPT ingilizce sorunca anladı sorunu çözdüm

    import random
    # specify the file path
    file_path = "xxx.txt"
    # read the file and save the lines in a list
    with open(file_path) as f:
        lines = f.readlines()
    # select a random line
    random_line = random.choice(lines)
    # remove the selected line from the list
    lines.remove(random_line)
    # write the remaining lines back to the file
    with open(file_path, "w") as f:
        f.writelines(lines)
    # print the selected line
    print(random_line)
  • 11-12-2022, 14:19:40
    #3
    kuklux adlı üyeden alıntı: mesajı görüntüle
    ChatGPT ingilizce sorunca anladı sorunu çözdüm

    import random
    # specify the file path
    file_path = "xxx.txt"
    # read the file and save the lines in a list
    with open(file_path) as f:
        lines = f.readlines()
    # select a random line
    random_line = random.choice(lines)
    # remove the selected line from the list
    lines.remove(random_line)
    # write the remaining lines back to the file
    with open(file_path, "w") as f:
        f.writelines(lines)
    # print the selected line
    print(random_line)
    ChatGPT nedir?
  • 11-12-2022, 14:20:01
    #4
    php_bot adlı üyeden alıntı: mesajı görüntüle
    ChatGPT nedir?
    https://chat.openai.com/chat