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?
python random veriyi çektikten sonra silmek
3
●88
- 11-12-2022, 14:12:02
- 11-12-2022, 14:13:49ChatGPT 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:20:01https://chat.openai.com/chatphp_bot adlı üyeden alıntı: mesajı görüntüle
